[英]Development web server fires Application_Error on 404, why doesn't IIS7?
I'm using Application_Error to catch some legacy URLs and URL shortcuts. 我正在使用Application_Error来捕获一些遗留URL和URL快捷方式。 In Global.vb I have this code:
在Global.vb中我有这个代码:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim serverError = TryCast(Server.GetLastError(), HttpException)
If serverError IsNot Nothing Then
Dim errorCode As Integer = serverError.GetHttpCode()
If 404 = errorCode Then
' Do some custom processing here
End If
End If
End Sub
In web.config I have this, to ensure that all requests, not just ones ending in .aspx, are handled by aspnet_isapi.dll so I get to process them: 在web.config中我有这个,以确保所有请求,而不仅仅是以.aspx结尾的请求,由aspnet_isapi.dll处理,所以我得处理它们:
<add name="ASP.NET-ISAPI-2.0-Wildcard" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
On my development box (using Cassini), this works fine in all cases: Both /badurl and /badurl.aspx cause Application_Error to fire. 在我的开发框中(使用Cassini),这在所有情况下都能正常工作:/ badurl和/badurl.aspx都会导致Application_Error触发。
In IIS7, however, /badurl.aspx works as expected, but /badurl just results in a generic server-generated 404 page. 但是,在IIS7中,/ badur.aspx按预期工作,但/ badurl只会导致通用服务器生成的404页面。
Any ideas what causes the difference, and how I can get IIS7 to replicate the development server's behavior? 是什么导致差异的想法,以及我如何让IIS7复制开发服务器的行为?
try to add this to web.config file. 尝试将此添加到web.config文件。
<customErrors mode="On" defaultRedirect="appError.aspx">
<error statusCode="403" redirect="appError.aspx"/>
<error statusCode="404" redirect="appError.aspx"/>
</customErrors>
You can try in two ways: 你可以尝试两种方式:
Response.TrySkipIisCustomErrors = true;
Response.TrySkipIisCustomErrors = true;
<customErrors redirectMode="ResponseRewrite mode="On" defaultRedirect="appError.aspx" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.