Copied to clipboard

Flag this post as spam?

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


  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Oct 04, 2010 @ 15:25
    Tim
    1

    Get Custom Not Found Page to Return 404 Status Code?

    Is it possible to get Umbraco to return a "proper" 404 status code instead of 200 OK for the custom page not found page? I know the standard .Net error handling does the same thing, but I can get round that by adding:

    Response.StatusCode = 404; 

    to the page. If I try and do the same in Umbraco, it just fires off the 404 handler again, effectively resulting in an infinite loop as the custom 404 page throws a 404 status, and then gets redirected back to itself and so on.

    I've not really found much on this from looking so far, I'm sure someone must have found a way round this! Any help or pointers greatly appreciated.

    :)

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Oct 04, 2010 @ 16:00
    Tim
    2

    Sorted, I needed to tell it to ignore IIS errors as well. Adding the following code to the template for the 404 page sorts it (you could add similar code in an XSLT extension I guess too):

    protected override void Render(HtmlTextWriter writer)
    {
        base.Render(writer);
        Response.TrySkipIisCustomErrors = true;
        Response.StatusCode = 404;
        Response.StatusDescription = "404 Page Not Found";
    }

    This is the important bit: Response.TrySkipIisCustomErrors = true; if you don't have that line in and you're running IIS7 or above, you'll run into the infinite looping that I described earlier! Hope that helps anyone else who has this problem!

  • David Conlisk 432 posts 1008 karma points
    Apr 23, 2012 @ 12:55
    David Conlisk
    0

    Excellent Tim - thanks!

  • John Perryn 71 posts 182 karma points
    Dec 23, 2013 @ 15:30
    John Perryn
    0

    Hi Tim

    I'm having exactly this problem - all url errors are routed to my 404 page which works OK but the page returns "200 OK" to the caller.

    I do not understand how to "add the code to the 404 template".

    I'm running umbraco v 4.11.8

    Regards

    John Perryn

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Dec 23, 2013 @ 15:43
    Tim
    0

    Hi John,

    Umbraco 4.11.8 should return actual 404 statuses for not found content (this was a bug on much older versions of Umbraco). How have you wired in the 404 page? Are you using the customerrors section in the web.config file, or the Umbraco 404 page configuration in umbracoSettings.config?

  • John Perryn 71 posts 182 karma points
    Dec 24, 2013 @ 00:34
    John Perryn
    0

    Hi Tim, and thanks.

    You can see my error 404 page here http://www.qfhs.org.au/zzzz

    I'm using the Chrome extension "Postman" to view headers etc. This clearly shows  200 OK for the above link

    web.config has only  [customErrors mode="RemoteOnly" defaultRedirect="runtime_error/" /]

    The runtime_error page appears correctly in stead of YSOD. eg http://www.qfhs.org.au/xxx/%20 however this page also returns status 200 OK to the user.

    umbracoSettings.config has:  [error404] 1075 [/error404]

    IIS server custom error handler for 404 redirects to http://www.qfhs.org.au/error-page/   which has nodeId = 1075 of course.

    I'm also using the Umbraco package URL Tracker v2.2.3 by Stefan Kip. This and Google Webmaster Tools confirm that there are hundreds of dead links from our previous site still considered to be "OK" and therefore working in the live site.

    Regards and thanks again

    John Perryn

     

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Dec 24, 2013 @ 09:54
    Tim
    0

    The built in IIS error handlers using the CustomErrors section in web.config all return 200 statuses, something I REALLY wish Microsoft would fix, as its wrong.

    I'm wondering if the IIS error setting is overriding the Umbraco one. In your umbracoSettings.config file, there should be a setting called "trySkipIisCustomErrors" near the bottom somewhere. Try setting that to true and see if it solves the 404 returning the wrong status!

  • John Perryn 71 posts 182 karma points
    Dec 24, 2013 @ 23:39
    John Perryn
    0

    Hi Tim

    Yes, excellent. That appears to have worked. A simple test is showing 404 again. I'll do more testing but happy to mark that as a soved problem.

    Merry Christmas from Australia.

    John Perryn

  • John Perryn 71 posts 182 karma points
    Dec 26, 2013 @ 14:57
  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Jan 13, 2014 @ 10:10
    Tim
    0

    Hi John,

    My guess would be that the first and last are being handled by Umbraco, but the other two are being handled by the IIS handler (as they're not file types that are usually handled by the ASP.Net pipeline).

    Try setting a different URL for the IIS 404 to see if that's the case. If it is, you may need to map the .asp/.html extensions to the aspnet ISAPI filter. Does your site make use of asp/vbscript or plain html files?

  • aaronb 97 posts 116 karma points
    Feb 06, 2014 @ 04:09
    aaronb
    0

    Tim, any chance you could explain the mapping in more detail please? I followed the steps here and am seeing exactly the same as John. although my pages which are coming back as 200 are using the custom 404 page, while the ones returning actual 404 codes are using the 'this page intentionally left ugly' page.

  • John Perryn 71 posts 182 karma points
    Feb 06, 2014 @ 05:14
    John Perryn
    0

    Thanks Aaron.

    Tim, there are no  asp/vbscript or plain html being used. And RE: "...different URL for the IIS 404..." -  and - ".. map the .asp/.html extensions..." these are beyond my reach.

    Rgds

    John P

  • yogesh pathak 136 posts 221 karma points
    Dec 17, 2015 @ 09:47
    yogesh pathak
    0

    Hi All, I am having the same issue , custom 404 returning status code 200 Ok , how to fix this in umbraco 7.2 any help?

    Yogesh

  • Shaun 248 posts 475 karma points
    Oct 27, 2016 @ 09:14
    Shaun
    0

    Did you ever work out a solution for this yogesh? I'm having the same issue.

  • Comment author was deleted

    Oct 27, 2016 @ 09:30

    You can also just use this package https://our.umbraco.org/projects/backoffice-extensions/umbraco-page-not-found-manager/ , should return the correct code

  • Shaun 248 posts 475 karma points
    Oct 27, 2016 @ 10:20
    Shaun
    0

    Hi Tim

    Thanks for that.

    I installed it on my local build and I could right click my home node in the content menu, and by selecting the 404 page I could set it.

    However, when I installed it on my development server the following happens.

    I right click the home node in the content menu, select 404, and instead of showing me the content picker it loads the 404 page itself into the window!

    I am using Umbraco version 7.3.1 assembly: 1.0.5780.28249

    Any hints or tips?

  • Comment author was deleted

    Oct 27, 2016 @ 10:29

    Same Umbraco version?

  • Shaun 248 posts 475 karma points
    Oct 27, 2016 @ 10:35
    Shaun
    0

    yes, its the same on my local and development build

    I've tried removing the error settings in umbracosettings.config and on IIS and now the window is blank, looks like there's something missing from the package install on the development build but I can't see what.

  • yogesh pathak 136 posts 221 karma points
    Oct 27, 2016 @ 10:38
    yogesh pathak
    1

    Hey Shaun, try setting up trySkipIisCustomErrors=false in your UmbracoSettings.config

    see the screenshot

    Yogeshenter image description here

  • Shaun 248 posts 475 karma points
    Oct 27, 2016 @ 13:20
    Shaun
    0

    I have just tried your method using theskipTisCustomErrors on a 7.2.1 build Yogesh, but sadly I get config errors. It doesn't recognise disableAlternativeTemplates or disableFindContentByIdPath

  • Shaun 248 posts 475 karma points
    Oct 27, 2016 @ 10:41
    Shaun
    0

    Thanks Yogesh. Did you use this in addition to the page not found package that Tim has suggested, or as an alternative?

  • yogesh pathak 136 posts 221 karma points
    Oct 27, 2016 @ 10:52
    yogesh pathak
    0

    no i am not using any package, just the 404 page id setting and this one

  • Shaun 248 posts 475 karma points
    Oct 27, 2016 @ 11:05
    Shaun
    0

    Thanks Yogesh

    I persevered with the package and found that locally I had files in App_Plugins/PageNotFoundManager, whereas on the server that file did not exist.

    I checked the permissions settings for V7 and it doesn't mention the App+Plugins folder, but I added permissions to that anyway and uninstalled/reinstalled the package

    after installing the page displayed a file not found message and the site went down due to an error in the web.config. I tweaked it to read

    <httpErrors existingResponse="PassThrough">
                <remove statusCode="404" subStatusCode="-1" />
                <error statusCode="404" prefixLanguageFilePath="" path="/four-oh-four/" responseMode="ExecuteURL" />
            </httpErrors> 
    

    I was then able to set the 404 page in the content tree. and the package worked perfectly!

    My 404 custom page now returns 404 status!

  • yogesh pathak 136 posts 221 karma points
    Oct 27, 2016 @ 11:08
    yogesh pathak
    0

    great, cheers :)

    Yogesh

  • Jeremy Schlosser 14 posts 84 karma points
    Jan 10, 2018 @ 17:58
    Jeremy Schlosser
    0

    Running 7.5.8 here. The above solution did not provide the 404 status code for me. What worked is setting httpErrors response to "PassThrough" and in UmbracoSettings.config, specifying the 404's page id in a <error404> tag. It's described here: http://letswritecode.net/articles/how-to-setup-custom-error-pages-in-umbraco/ I think setting the response to PassThrough means I will also need to configure the 404 error page in IIS.

Please Sign in or register to post replies

Write your reply to:

Draft