Welcome 微信登录

首页 / 网页编程 / ASP.NET / 代码阅读总结之Fitch and Mather 7.0

代码阅读总结之Fitch and Mather 7.02012-01-18 博客园 aierongasp.net发生异常或错误时错误提示页面的处理方法

当asp.net发生异常或错误时,我们是怎么样处理错误提示页面?

我总结了下面几种方式:

i:利用方法Response.Redirect()

看下面2段代码:

1.

在页面admin.aspx中发生异常时

try{    //程序逻辑}catch(OverflowException){    //在选中的上下文中所进行的算术运算、类型转换或转换操作导致溢出时引发的异常    //例如:小于int的MinValue或大于int的MaxValue,异常,转到出错误页    Response.Redirect("ErrorPage.aspx",true);}
2.

在开源项目ASP.NET StartKit TimeTracker中

在页面UserList.aspx中发生逻辑错误

if (TTSecurity.IsInRole(TTUser.UserRoleAdministrator) == false){    //访问者的角色不是"Administrator"时,提示角色错误页面    Response.Redirect("AccessDenied.aspx?Index=-1", true);}
ii.利用配置文件Web.config

我们先设定

<customErrors  mode="On"  defaultRedirect="ErrorPage.aspx"  />