在我的Asp.Net MVC项目中,我正在处理Http FileNotFound Exceptions(针对丢失的图像),然后将请求重定向到如下所示的默认图像
protected void Application_Error(object sender, EventArgs e)
{
if (Request.Path.StartsWith("/images/profile"))
{
Response.Redirect("/images/profile/default.jpg", true);
return;
}
}
当我调试网站时,它正在开发环境中工作。但是,当我将其部署到运行IIS 7.5的生产服务器时,此代码不起作用,对图像文件的请求不会触发Application_Error事件。 IIS上有任何配置吗?我找不到问题。
最佳答案
您需要将IIS配置为通过ASP.Net运行所有请求。
将<modules runAllManagedModulesForAllRequests="true" />
添加到Web.config中的<system.webServer>
中。
另外,您应该为此添加一条路由,而不是处理Error
事件。
关于asp.net - 静态文件请求不会引发application_error事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5671946/