IIS 404 Custom Error not working as expected

后端 未结 4 573
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 13:13

I\'m working on IIS6, ASP.NET, VS2008. The web site uses a custom error handler to catch 404 errors and serve an alternate page. When presented with an url of the form:

4条回答
  •  醉梦人生
    2020-12-20 13:58

    hmm, Assaf is right, but to add to his answer I need to post some code.

    Yes, Assaf does mean something else ASP.NET offers it's own error handling, configured through the web.config. You can either manage this through the IIS Admin snap in, or directly in the web.config file.

    Within the element you should have:

    
      
    
    

    You can configure a different page for each HTTP error code, or let the default redirect handle them all.

    You'll find that you do indeed need to set these error pages up in both the IIS custom errors and the ASP.NET configuration, as otherwise you'll end up in this situation - some pages go to your 404, and others use a default that you've not customised.

    You should also make sure that your custom 404 page actually returns a 404 header to ensure that search engines etc treat it correctly.

    Response.StatusCode = 404;
    Response.StatusDescription = "Not found";
    

提交回复
热议问题