Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chad Rosenthal 272 posts 474 karma points
    Apr 19, 2013 @ 16:00
    Chad Rosenthal
    0

    Custom 404 Handler never gets called

    I created a custom 404 handler for v6.0.2. I followed the information here: http://our.umbraco.org/wiki/how-tos/how-to-implement-your-own-404-handler.

    My code for the handler is:

    using System.Configuration;
    using umbraco.interfaces;
    
    namespace TempNamespace.Web
    {
        public class LocalizedNotFoundHandler : INotFoundHandler
        {
            private int redirectId;
    
            public bool Execute(string url)
            {
                try
                {
                    var errorPage = ConfigurationManager.AppSettings["errorPageId"];
                    int errorPageId;
    
                    if (!int.TryParse(errorPage, out errorPageId))
                    {
                        return false;
                    }
    
                    redirectId = errorPageId;
                    return true;
                }
                catch
                {
                    return false;
                }
            }
    
            public bool CacheUrl
            {
                get { return false; }
            }
    
            public int redirectID
            {
                get { return redirectId; }
            }
        }
    }

     

    Then I updated the 404handler.config:

    <?xml version="1.0" encoding="utf-8"?>
    <NotFoundHandlers>
        <notFound assembly="umbraco" type="SearchForAlias" />
        <notFound assembly="umbraco" type="SearchForTemplate" />
        <notFound assembly="umbraco" type="SearchForProfile" />
        <notFound assembly="SEOChecker" type="Handlers.NotFoundHandlers.Inbound404Handler" />
        <notFound assembly="TempNamespace.Web" type="TempNamespace.Web.LocalizedNotFoundHandler" />
    <notFound assembly="umbraco" type="handle404" /> </NotFoundHandlers>

     

    The SEOChecker is working just fine, and the umbraco handle404 is working correctly. But my code never works. I've tried to remove SEOChecker and handle404, and still nothing. Between every change, i've been updating the web.config so that the app refreshes.

    Ideas?

    -C

     

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 19, 2013 @ 16:22
    Alex Skrypnyk
    0

    Hi Chad,

    Are you sure that <notFoundassembly="ASSEMBLYNAME"namespace="YOURNAMESPACE"type="HANDLERCLASS"/> you write in right way ?

    THanks,

    Alex

  • Chad Rosenthal 272 posts 474 karma points
    Apr 19, 2013 @ 16:31
    Chad Rosenthal
    0

    I just retried it.

        <notFound assembly="TempNamespace.Web" namespace="TempNamespace.Web" type="LocalizedNotFoundHandler" />

    No luck.

    -C

     

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 19, 2013 @ 16:33
    Alex Skrypnyk
    0

    Type should be full name.

    Problem definitely is in this Config.

  • Chad Rosenthal 272 posts 474 karma points
    Apr 19, 2013 @ 23:03
    Chad Rosenthal
    0

    I ever removed all of my code and just use the generic implementation of INotFoundHandler and still no luck. There went my day, and I know it's a stupid user error too...

    -C

  • Chad Rosenthal 272 posts 474 karma points
    Apr 19, 2013 @ 23:45
    Chad Rosenthal
    0

    Here is my trace, my code never gets called.

    2013-04-19 17:43:56,731 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering custom handlers.

    2013-04-19 17:43:56,732 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'umbraco.SearchForAlias,umbraco'.

    2013-04-19 17:43:56,734 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'umbraco.SearchForTemplate,umbraco'.

    2013-04-19 17:43:56,734 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'umbraco.SearchForProfile,umbraco'.

    2013-04-19 17:43:56,734 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'SEOChecker.Handlers.NotFoundHandlers.Inbound404Handler,SEOChecker'.

    2013-04-19 17:43:56,736 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'TempNamespace.Web.LocalizedNotFoundHandler,TempNamespace.Web'.

    2013-04-19 17:43:56,737 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'umbraco.handle404aaa,umbraco'.

    2013-04-19 17:43:56,738 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Running for legacy url='asdf'.

    2013-04-19 17:43:56,739 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Handler 'umbraco.SearchForAlias'.

    2013-04-19 17:43:56,740 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Replace handler 'umbraco.SearchForAlias' by new lookup 'Umbraco.Web.Routing.LookupByAlias'.

    2013-04-19 17:43:56,742 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Handler 'umbraco.SearchForTemplate'.

    2013-04-19 17:43:56,742 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Replace handler 'umbraco.SearchForTemplate' by new lookup 'Umbraco.Web.Routing.LookupByNiceUrlAndTemplate'.

    2013-04-19 17:43:56,761 [11] DEBUG Umbraco.Web.Routing.LookupByNiceUrlAndTemplate - [Thread 30] Not a valid template: "asdf"

    2013-04-19 17:43:56,761 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Handler 'umbraco.SearchForProfile'.

    2013-04-19 17:43:56,761 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Replace handler 'umbraco.SearchForProfile' by new lookup 'Umbraco.Web.Routing.LookupByProfile'.

    2013-04-19 17:43:56,762 [11] DEBUG Umbraco.Web.Routing.LookupByProfile - [Thread 30] Not the profile path

    2013-04-19 17:43:56,762 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Handler 'SEOChecker.Handlers.NotFoundHandlers.Inbound404Handler'.

    2013-04-19 17:43:56,773 [11] WARN  Umbraco.Web.Routing.NiceUrlProvider - [Thread 30] Couldn't find any page with nodeId=-1. This is most likely caused by the page not being published.

    2013-04-19 17:43:56,774 [11] DEBUG Umbraco.Core.PluginManager - [Thread 30] LookupDocument: End resolvers, no document was found (took 49ms)

  • Chad Rosenthal 272 posts 474 karma points
    Apr 22, 2013 @ 15:01
    Chad Rosenthal
    100

    So my issue had nothing to do with the code. Because I have the code in a project, I needed to set the Build Action to 'Compile'. Voila. It now works.

    -C

     

  • Jeric 122 posts 192 karma points
    Jul 21, 2013 @ 17:04
    Jeric
    0

    Hi Chad,

    I'm having the same issue as the Custom 404 Handler are not being called.

    For the <notFound> part which did you used for it to work as below?

    a) <notFoundassembly="TempNamespace.Web"type="TempNamespace.Web.LocalizedNotFoundHandler"/>

    b) <notFoundassembly="TempNamespace.Web"type="LocalizedNotFoundHandler"/>

      c)  <notFound assembly="TempNamespace.Web" namespace="TempNamespace.Web" type="LocalizedNotFoundHandler" />

     

    One more thing, inside your UmbracoSettings.config as below.
    Do you leave your <error404></error404> empty?

     <errors>

          <!-- the id of the page that should be shown if the page is not found -->

          <!--        <errorPage culture="default">1</errorPage>-->

          <!--        <errorPage culture="en-US">200</errorPage>-->

          <error404>1088</error404>

        </errors> 

     

Please Sign in or register to post replies

Write your reply to:

Draft