in my Asp.Net MVC project I'm cathing Http FileNotFound Exceptions (for a missing image) and then redirect request to a default image like below
protected void Application_Error(object sender, EventArgs e)
{
if (Request.Path.StartsWith("/images/profile"))
{
Response.Redirect("/images/profile/default.jpg", true);
return;
}
}
It is working in development envirement when I am debugging my website. But when I deploy it to production server that runs IIS 7.5 This code isn't workin开发者_如何学编程g, request to a image file does not trigger the Application_Error event. Is there any configuration on IIS? I can't find the problem.
You need to configure IIS to run all requests through ASP.Net.
Add <modules runAllManagedModulesForAllRequests="true" />
to <system.webServer>
in Web.config.
Also, you should add a route for this instead of handling the Error
event.
精彩评论