0

在我的 Asp.Net MVC 项目中,我正在处理 Http FileNotFound 异常(对于丢失的图像),然后将请求重定向到默认图像,如下所示

  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上有什么配置吗?我找不到问题。

4

1 回答 1

1

您需要配置 IIS 以通过 ASP.Net 运行所有请求。

添加<modules runAllManagedModulesForAllRequests="true" /><system.webServer>Web.config 中。


此外,您应该为此添加路由而不是处理Error事件。

于 2011-04-15T03:13:33.777 回答