IIS 404 Custom Error not working as expected

空扰寡人 提交于 2019-11-27 07:40:48

问题


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:

http://srv/crimson/articles/index

Everything works perfectly. But an url of the form:

http://srv/crimson/blog.aspx

Where blog.aspx does not exist, fails with the following message:

Server Error in '/Crimson' Application. Description: HTTP 404...

When I try and debug, none of the breakpoints in my 404 handler are hit. So it appears that something is catching the request earlier. Where? And how to I get it to pass the request on to my handler?

Edit Thanks to those who answered, but none of those ideas worked. I've decided to attack the problem another way.


回答1:


You might wanna try this:

In IIS6:

  • open "properties" for your website
  • go to "home directory" tab
  • click on "configuration"
  • look for the extension ".aspx"
  • click on "edit"
  • check the checkbox which says "verify that file exists"

edit

And what about this: http://msdn.microsoft.com/en-us/library/h0hfz6fc(VS.80).aspx

<customErrors defaultRedirect="sorry.htm" mode="On">  
     <error statusCode="404" redirect="NotFound.aspx"/>
</customErrors>

Since 'RemoteOnly' specifies that custom errors are shown only to the remote clients, and that ASP.NET errors are shown to the local host.




回答2:


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 <system.web> element you should have:

<customErrors defaultRedirect="sorry.htm" mode="RemoteOnly">
  <error statusCode="404" redirect="NotFound.aspx"/>
</customErrors>

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";



回答3:


ASP.Net has a custom errors configuraiton of its own.

Go to the ASP.Net configuration of your virtual directory (web application) and right-click -> ASP.Net -> Edit Configuration -> Custom Errors.




回答4:


Maybe you got a 500 so redirect for 404 is not triggered. You may focus on this 500 error at first.



来源:https://stackoverflow.com/questions/615829/iis-404-custom-error-not-working-as-expected

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!