错误页

  1. 错误页配置(web.config):

①<customErrors mode=“On” defaultRedirect=“~/GenericErrorPage.htm”>

  <error statusCode=“403” redirect=“NoAccess.htm” />

  <error statusCode=“404” redirect=“FileNotFound.htm” />

</customErrors>

②mode的三个可选值(On Off RemoteOnly):

On: 总显示定制错误页

Off: 总显示调用堆栈等异常信息

RemoteOnly: 对于本机显示调用堆栈等异常信息 对于外部用户显示定制错误页(页可以在错误页中通过Request.UserHostAddress来设置某些IP对错误信息可见 页可以通过Session进行设置)

  1. 错误页可以使用htm & aspx页面:

①aspx页面中使用HttpContext.Current.Server.GetLastError()拿到异常对象并使用Log4Net等将异常记录到系统日志

②<customErrors redirectMode=“ResponseRewrite” />设置重定向方式为内部重定向(等同于Server.Transfer()重定向方式)

posted on 2011-09-20 16:50  les_vies  阅读(294)  评论(0编辑  收藏  举报

导航