mjb*_*mjb 7 asp.net web-config c#-4.0
这些是web.config中的代码:
<system.web>
<customErrors mode="Off" >
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<clear />
<error statusCode="404" prefixLanguageFilePath="" path="/ResourceNotFound" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/ResourceNotFound" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
以上设置仅重定向404和500的httpError.
但不是手动添加400,401,403 ....等所有错误代码... ...
我们可以设置它将所有错误重定向到相同的URL而不键入所有错误代码吗?
<error statusCode="400" .....
<error statusCode="401" .....
<error statusCode="403" .....
<error statusCode="404" .....
<error statusCode="xxx" ....
Run Code Online (Sandbox Code Playgroud)
试试这个,
添加web.config文件.
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File" >
<remove statusCode="500" />
<error statusCode="500" prefixLanguageFilePath="C:\Contoso\Content\errors"
path="500.htm" />
</httpErrors>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
和
<httpErrors existingResponse="Replace" defaultResponseMode="ExecuteURL" errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
<remove statusCode="401" />
<error statusCode="401" path="/Account/Login.aspx" responseMode="ExecuteURL"/>
<remove statusCode="501"/>
<error statusCode="501" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
<remove statusCode="411"/>
<error statusCode="411" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
<remove statusCode="403"/>
<error statusCode="403" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
</httpErrors>
Run Code Online (Sandbox Code Playgroud)
更多关于这个http://www.iis.net/configreference/system.webserver/httperrors
该httpErrors部分具有defaultPath属性.
<system.webServer>
<httpErrors defaultPath="Error.html" defaultResponseMode="File">
<clear />
</httpErrors>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
http://www.iis.net/configreference/system.webserver/httperrors
但是,我不使用它,因为defaultPath默认情况下锁定在IIS Express中.需要编辑%homepath%\Documents\IISExpress\config\applicationHost.config才能解锁.
<httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
<!-- ... -->
</httpErrors>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15870 次 |
| 最近记录: |