locked
Custom error page not working correctly. RRS feed

  • Question

  • User-79977429 posted

    Hi

    i've add this xml tag inside my web.config file to handle 404 error :

    ...
    <customErrors mode="On" defaultRedirect="~/Error.aspx">
    			<error statusCode="404" redirect="~/Error.aspx"/>
    		</customErrors>
    ...

    This works when i open invalid aspx page such as

    http://www.houshmand.ir/InvalidPage.aspx

    but if open this address, the default iis error page shown instead of my custom error page :

    http://www.houshmand.ir/22222

    Also, in some online seo checkers (such as this), i'm facing the "Custom 404 Page" negative value problem!! I think it can not detect my error page.

    What's the problem and how to solve that?

    Thanks in advance

    Sunday, March 29, 2020 2:41 PM

Answers

  • User-1330468790 posted

    Hi hamed_1983,

     

    I presume that you are constructing a webform project since I think the setting you used will not bother you in MVC project.

    Solution:

    The solution is to change the httperrors' mode to 'Custom' and remove the '404' default error page and add your error handler for the web server.

    Settings:

     <system.web>
    ......
        <customErrors mode="On" defaultRedirect="~/Error.aspx">
          <error statusCode="404" redirect="~/Error.aspx"/>
        </customErrors>
    ......
      </system.web>
     <system.webServer>
    ......
        <httpErrors errorMode="Custom">
          <remove statusCode="404"/>
          <error statusCode="404" path="Error.aspx" responseMode="Redirect"/>
        </httpErrors>
    ......
      </system.webServer>

     
     More information about <httpErrors>, you can refer to below link:

    https://docs.microsoft.com/en-us/iis/configuration/system.webserver/httperrors/

     

    Also, in some online seo checkers (such as this), i'm facing the "Custom 404 Page" negative value problem!! I think it can not detect my error page.

    I am not familiar with SEO checkers and the problem of the nagative value. However, based on your problem of the 'Custom 404 Page', I can do a guess that it might be caused by a failure/absence to provide a redirect page for 404 error.

     

    Hope this can help you.

    Best regards,

    Sean

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 30, 2020 3:01 AM