asp.net 错误页面自定义

在我们上网浏览信息的时候,总会有出现404页面的时候,在我们开发的时候也可以自定义这些页面。刚回这次项目中也使用到了,就在网上找到一些方法,今天就把这些方法重新写一遍加深记忆。

在项目的web.config中的<system.webServer>节点添加

<customErrors mode="On" defaultRedirect="ApplicationErroy.aspx" >
<error statuscode="500"redirect="index.aspx" /> <!--error 节点 分别控制错误码显示的页面,非必须-->
<error statuscode="404"redirect="index.aspx" />
<error statuscode="403"redirect="index.aspx" />
</customErrors>
defaultRedirect是出现错误,跳转到指定的页面

这里面Mode有三个选择,

1.On 一直控制,如果出现异常,则跳转到默认的页面

2.Off 关闭,不使用

3.RemoteOnly  在服务器端显示错误,在客户端显示跳转页面

例外一种方法就是

未完

原文地址:https://www.cnblogs.com/xinqi1995/p/8253660.html