Copied to clipboard

Flag this post as spam?

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


  • Stuart Paterson 57 posts 228 karma points
    Jun 11, 2020 @ 07:18
    Stuart Paterson
    0

    Custom 404 page returns 200 status

    Hi,

    We have an external agency auditing our site at the moment and one of the recommendations they have is to return a 404 response code for the actual custom 404 page itself.

    Our custom 404 works fine in every other respect, so if you generate a 404 page by deliberately going to a non-existent page the correct 404 response is generated.

    The custom 404 page /404/ returns 200 I guess because it's a valid page which exists in Umbraco. Is there anyway to force this to also have a 404 response code?

    For info, I'm specifying my 404 in the umbracoSettings.config

        <errors>
      <error404>15969</error404>
      <!-- 
        The value for error pages can be:
        * A content item's integer ID   (example: 1234)
        * A content item's GUID ID      (example: 26C1D84F-C900-4D53-B167-E25CC489DAC8)
        * An XPath statement            (example: //errorPages[@nodeName='My cool error']
      -->
      <!--
        <error404>
            <errorPage culture="default">1</errorPage>
            <errorPage culture="en-US">200</errorPage>
        </error404>
       -->
    </errors>
    

    In the web.config I have

        <httpErrors existingResponse="PassThrough" />
    

    Thanks Stuart

  • Nik 1599 posts 7179 karma points MVP 6x c-trib
    Jun 11, 2020 @ 07:54
    Nik
    101

    Hi Stuart,

    Yes, you can change the response code. You can set it in the view by doing something like Response.StatusCode = 404 I think.

    I don't have sample code to hand but it can be done that way. It might be more like Request.Response.SetStatusCode or something similar

    Nik

  • Stuart Paterson 57 posts 228 karma points
    Jun 11, 2020 @ 13:22
    Stuart Paterson
    0

    wow...that was simpler than I thought haha

    Thanks a lot Nik, works perfectly...I was thinking that i'd missed something in an Umbraco config file somewhere or web.config setting.

        @{ 
        if (Request.Url.ToString().Contains("404"))
        {
            Response.StatusCode = 404;
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft