web.config 404中的customErrors有效,404.0没有

时间:2012-12-15 23:34:15

标签: asp.net asp.net-mvc iis asp.net-mvc-4 web-config

我已经设置了自定义404并且它有效。但是当我尝试访问一些不存在的文件时,它显示了很好的'ASP.NET 404.0错误页面。

我尝试添加<error statusCode="404.0" redirect="/notfound/?" />,但由于statusCode应为整数,因此无效。

实施例

http://localhost:123/das/dsagfdsa将重定向到http://localhost:123/notfound/? http://localhost:123/das/dsagfdsa.png会留下并显示404.0错误。

自定义错误部分

<customErrors mode="On" redirectMode="ResponseRedirect" defaultRedirect="/notfound/?">
    <error statusCode="404" redirect="/notfound/?" />
</customErrors>

问题

如何确保它不仅会在错误的网页请求中重定向到/notfound/,还会在错误的文件请求中重定向到<{p}}?

1 个答案:

答案 0 :(得分:1)

您必须在IIS中进行配置。默认情况下,只有特定文件将通过ASP.NET框架路由,否则IIS将处理它(配置如下面IIS的“错误页面”部分所示)。

或者,您也可以将ASP.NET配置为处理其他文件类型。有关详细信息,请参阅Handler Mappings

enter image description here