IIS 7.0 404自定义错误页面和web.config

我遇到了自定义404错误页面的问题。

我有一个域运行一个.NET proj自己的error handling。 我有一个web.config运行的域包含:

<customErrors mode="RemoteOnly"> <error statusCode="500" redirect="/Error"/> <error statusCode="404" redirect="/404"/> </customErrors> 

在该域的子目录中,我忽略了所有的路由,通过执行routes.IgnoreRoute("Assets/{*pathInfo}"); 在.NET proj中,我想把一个自定义的404错误页面和资产的任何子目录。 子目录包含静态内容,如图像,CSS,JS等。

所以在IIS的错误页面部分,我把redirect到一个绝对的URL。

该目录的web.config如下所示:

 <system.webServer> <httpErrors> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" prefixLanguageFilePath="" path="http://mydomain.com/404" responseMode="Redirect" /> </httpErrors> </system.webServer> 

但我导航到该目录下的一个未知的URL,但我仍然看到默认的IIS 404页面。

我也看到在IIS中的一个警报:

您已经为本地和远程请求configuration了详细的错误消息。 当select此选项时,不使用自定义错误configuration。

这与网站web.config中的customErrors mode="RemoteOnly"有什么关系?

我试图覆盖子目录web.config中的customErrors ,但没有改变。

任何帮助,将不胜感激。

谢谢。

你可以尝试添加这个:

 <httpErrors> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" prefixLanguageFilePath="" path="/index.php" responseMode="ExecuteURL" /> </httpErrors> 

在你的“web.config”文件中。

这可能有点晚,但是你可以把下面的内容放在web.config的system.webserver部分

 <system.webServer> <httpErrors existingResponse="PassThrough" /> </system.webServer> 

信贷去堆栈溢出这个条目: https : //stackoverflow.com/questions/434272/iis7-overrides-customerrors-when-setting-response-statuscode