设置:Windows 7,IIS7.我正在开发一个通过本地IIS服务器查看的应用程序,而不是内置的调试Web服务器.所以我的应用网址是http://localhost/foo/bar.aspx
.有没有 <customErrors>
在我的web.config部分,我还没有在IIS中更改的设置.
如果发生任何错误,我总是会出现以下错误屏幕:
HTTP错误500.19 - 内部服务器错误 web.config文件中的部分不允许使用
绝对物理路径"C:\inetpub\custerr
"system.webServer/httpErrors
.请改用相对路径.
这是我的applicationhost.config
内容:
<httpErrors errorMode="Custom" lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
<error statusCode="401" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="401.htm" />
<error statusCode="403" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="403.htm" />
<error statusCode="404" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="404.htm" />
<error statusCode="405" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="405.htm" />
<error statusCode="406" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="406.htm" />
<error statusCode="412" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="412.htm" />
<error statusCode="500" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="500.htm" />
<error statusCode="501" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="501.htm" />
<error statusCode="502" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="502.htm" />
</httpErrors>
Run Code Online (Sandbox Code Playgroud)
如何摆脱此配置错误,以便查看详细错误?
我有简单的vanilla MVC4网络项目.没有添加,没有删除,只是在Visual Studio中创建了一个新项目.
在web.config
我添加了自定义错误页面处理程序:
<customErrors mode="On" defaultRedirect="~/Content/Error.htm" redirectMode="ResponseRewrite" />
Run Code Online (Sandbox Code Playgroud)
并且~/Content/Error.htm
文件是:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>OOPS! Error Occurred. Sorry about this.</title>
</head>
<body>
<h2>OOPS! Error Occurred</h2>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
每当我在网站上收到404错误时,Error.htm在Firefox和Chrome中作为纯文本提供:
Fiddler说错误页面没有content-type
标题,导致浏览器将页面呈现为纯文本:
有没有办法强制IIS服务器错误页面的content-type
头?
ps实际问题出在一个复杂的MVC4项目中,它在Global.asax中有自己的错误处理.但我发现有些错误不会通过ASP管道,只能由IIS处理.像网址末尾的点.使用<httpErrors />的解决方案确实提供了正确的响应,但我们在Global.asax,Application_Error()中的自定义错误处理不会以这种方式调用.
UPD似乎无法赢得这场战争.IE显示正确呈现的html,Firefox和Chrome显示为纯文本.当我切换到纯文本时,Firefox和IE正确显示空白区域,IE吞下白色空间并尝试渲染html.如果我尝试将图像作为错误页面提供,则Firefox和Chrome会显示图像.IE显示了这个:
捂脸!
我使用下面的web.config代码将请求重定向到缺少页面到404错误处理页面:
<customErrors mode="On" defaultRedirect="404.aspx" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="404.aspx"/>
</customErrors>
Run Code Online (Sandbox Code Playgroud)
当我查找诸如"missing.aspx"之类的页面时它工作正常,但它不适用于没有".aspx"扩展名的页面,例如"missing.asp"或只是"缺失".如果它不起作用,它只会加载标准的IIS 7.5错误页面.
我究竟做错了什么?我正在使用.net 4.我注意到其他人提出同样的问题,但他们没有得到答案.
谢谢!