Copied to clipboard

Flag this post as spam?

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


  • Braydie 148 posts 346 karma points
    May 23, 2013 @ 16:25
    Braydie
    0

    Not Found Handler in 4.11.8

    I've upgraded from 4.7.2 to 4.11.8 and have found that my not found handler is no longer working (nor firing). I've checked that my handler is in the 404handlers.config. 

    Here is my code:

    public class PageNotFoundHandler : INotFoundHandler   
        {
            private int RedirectNodeId;
    
            public bool Execute(string url)
            {
                string CurrentDomain = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
                int DomainRoot = Domain.GetRootFromDomain(CurrentDomain);
                Node HomePage = new Node(DomainRoot);
    
                RedirectNodeId = HomePage.GetPropertyInt(PropertyNames.ERROR_PAGE);
    
                if (RedirectNodeId == -1)
                {
                    RedirectNodeId = HomePage.Id;
                }
                return true;
            }
    
            public bool CacheUrl
            {
                get { return true; }
            }
    
            public int redirectID
            {
                get { return RedirectNodeId; }
            }
        }
  • Braydie 148 posts 346 karma points
    May 23, 2013 @ 16:25
    Braydie
    0

    I see the following exception when I go to a page that doesn't exist:

     

    Input string was not in a correct format.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.FormatException: Input string was not in a correct format.

    Source Error: 

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace: 

    [FormatException: Input string was not in a correct format.]
       System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +12636309
       System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +224
       Umbraco.Web.Routing.LookupByLegacy404.TrySetDocument(PublishedContentRequest pcr) +104
       Umbraco.Web.Routing.LookupByNotFoundHandlers.HandlePageNotFound(PublishedContentRequest docRequest) +818
       Umbraco.Web.Routing.LookupByNotFoundHandlers.TrySetDocument(PublishedContentRequest docRequest) +16
       System.Linq.Enumerable.Any(IEnumerable`1 source, Func`2 predicate) +149
       Umbraco.Web.Routing.PublishedContentRequestBuilder.LookupDocument1() +239
       Umbraco.Web.Routing.PublishedContentRequestBuilder.LookupDocument() +226
       Umbraco.Web.Routing.PublishedContentRequest.ProcessRequest(HttpContextBase httpContext, UmbracoContext umbracoContext, Action`1 onSuccess) +187
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270
  • Andreas Iseli 150 posts 427 karma points
    May 24, 2013 @ 10:06
    Andreas Iseli
    0

    What happens when you remove your handler?

  • Braydie 148 posts 346 karma points
    May 24, 2013 @ 10:54
    Braydie
    0

    Hi Andreas, if I remove the handler I still get the same issue :/

  • Andreas Iseli 150 posts 427 karma points
    May 24, 2013 @ 12:15
    Andreas Iseli
    0

    The I suggest to create an issue.. seems there is a problem in the core. I currently have no idea what it could be...

  • Braydie 148 posts 346 karma points
    May 24, 2013 @ 12:38
    Braydie
    0

    I feel a little bit closer to figuring out what the issue is - it seems that the exception was being thrown as it was assuming that I had an entry in my UmbracoSettings.config for my 404 page. I've put in a Node Id into the config and the page is now returned. Now the issue at hand is figuring out why Umbraco is ignoring my not found handler..!

  • Stephen 767 posts 2273 karma points c-trib
    May 24, 2013 @ 13:17
    Stephen
    0

    Hey, I guess I'm the cause of this since I rewrote that part between 4.7 and 4.10... bit busy today but I'm trying to figure out what your issue is. Stay tuned. In the meantime, anything new you can add here such as stacktraces, config details... whatever, can help.

  • Stephen 767 posts 2273 karma points c-trib
    May 24, 2013 @ 13:26
    Stephen
    0

    For thing: just reviewed the code for Umbraco.Web.Routing.LookupByLegacy404 and yes, it appears that we expect you to provide a nodeId in the /settings/content/errors/error404 section, or to remove that section entirely. If it's there but without a nodeId, we throw an exception. Granted, that's not really nice (although that's what happened in pre-4.10 I believe) and if you create an issue for it, I'll take care of it.

    Then, about your own custom handler: can you post the content of your 404handlers.config file? Still looking at that issue at the moment.

  • Stephen 767 posts 2273 karma points c-trib
    May 24, 2013 @ 13:32
    Stephen
    0

    One more thing... can you set <priority value="Debug"/> near the top of ~/config/log4net.config then fetch a page with your handler enabled, and post the relevant section of ~/App_Data/Logs/UmbracoTraceLog.txt (hopefully you'll find out what's "relevant" else post everything!).

  • Braydie 148 posts 346 karma points
    May 24, 2013 @ 15:19
    Braydie
    0

    Hi Stephen,

    Thanks for your reply, it's much appreciated. I've just tried to remove error section from the UmbraoSettings.config and it seems that no matter what I do with it I still get an exception thrown. If I remove the errors section I get a null reference exception, whereas if I just remove the errorPage block I get the format exception I posted earlier.

    My 404handlers.config looks like this:

     

    <?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="umbraco" type="handle404"/>
      <notFound assembly="MyAssembly.Library" type="PageNotFoundHandler"/>
      <notFound assembly="AutoFolders" type="NotFoundHandler"/>
    </NotFoundHandlers>

    Unfortunately my handler isn't being picked up at all, so I'm not having it logged in any way. I'm implementing INotFoundHandler, is this still correct or has it changed with the work done to the request pipeline?

     

  • Braydie 148 posts 346 karma points
    May 24, 2013 @ 15:59
    Braydie
    0

    Hi Stephen,

    I've just had another fiddle and my not found handler appears to be working now.. I think the issues I've faced have been as a result of the request pipeline work. To resolve my issue I've ensured that this is in my UmbracoSettings.config:

    <errors>
    <error404>
    <errorPage culture="en-GB">1</errorPage>
    </error404>
    </errors>

    I have a conflict with my log4net version because of a strong naming issue so Umbraco logging isn't working for me at the moment, so it's been a real bugger to figure out. I'm going to continue to have a prod around and see if I can figure out for sure what the issue was

  • Stephen 767 posts 2273 karma points c-trib
    May 24, 2013 @ 16:08
    Stephen
    100

    Your handler comes after the default handle404 so it probably never runs because handle404 takes care of everything... in order to make sure that your handler runs you will want to put it before handle404 in the configuration file.

    When you confgure the errorPage with an ID of 1 you ensure that the handle404 handler will not do anything because 1 is not a valid ID for a node... so you just seem to be trying to bypass that handler? Then again, just put yours before instead of after.

    Also it would really be a good idea if you could solve the log4net issue (with some binding redirects?) because the log would tell you whether it detects your handler, whether it tries to run it, etc.

  • Braydie 148 posts 346 karma points
    May 24, 2013 @ 18:11
    Braydie
    0

    Hi Stephen,

    Yep that was it!! I've just popped it all back and tested it with your post as reference and that was it! Seems so obvious now...! 

    And yeah, the logging issue is the next thing I'm hoping to tackle, it hasn't been enjoyable debugging blindly!

    Thanks for your help!

Please Sign in or register to post replies

Write your reply to:

Draft