错误处理机制跳转错误页面
来源:互联网 发布:练听力哪个软件好 知乎 编辑:程序博客网 时间:2024/06/15 07:15
版权声明:本文为博主原创文章,未经博主允许不得转载。
protected void Application_Error(object sender, EventArgs e)
{
HttpContext ctx = HttpContext.Current;
Exception exception = ctx.Server.GetLastError();
// Exception exception_s = Server.GetLastError();
//HttpException ex = exception_s as HttpException;
string directUrl = "Error.aspx?error=";
if (exception != null)
{
string m = exception.Message;
string errorInfo = "URL:<strong>" + ctx.Request.RawUrl.ToString() + "<strong><br/>Source:<strong>" + exception.Source
+ "<strong><br/>Message:<strong>" + exception.Message + "<>";
if (!m.Contains("不存在"))
{
errorInfo += "<br/>错误信息为:<strong>" + exception.InnerException.Message + "<>";
}
if (exception is HttpException)
{
HttpException ex = exception as HttpException;
int httpCode = ex.GetHttpCode();
errorInfo += "<br />Code:<strong>" + httpCode.ToString() + "<>";
}
string url = ctx.Request.Url.ToString();
string suburl = url.Substring(0, url.ToString().IndexOf("/Admin/") + 1);
directUrl = suburl + directUrl + errorInfo;
//directUrl += "&referurl=" + ctx.Request.Url.ToString();
//if (httpCode == 404)
//{
// directUrl = "~/DefaultError.html?error=" + errorInfo;
//}
//if (httpCode == 403 || httpCode == 402 || httpCode == 401)
//{
// directUrl = "~/DefaultError.html?error=" + errorInfo;
//}
//}
ctx.Items.Add("LastError", errorInfo);
ctx.Server.ClearError();
}
try
{
ctx.Response.Redirect(directUrl);
}
catch
{ }
//ctx.Server.Transfer(directUrl);
}
错误处理机制 代码, 要的赶紧粘贴到记事本
就写一个方法,页面所有报错 都指向一个页面就OK了
- 错误处理机制跳转错误页面
- 配置错误跳转页面
- jsp 错误页面跳转
- jsp中错误页面处理的跳转问题
- Android页面跳转错误解决
- JSPservlet跳转页面404错误
- asp错误处理机制
- 错误处理机制
- Kuix 错误处理机制
- .net错误处理机制
- .net错误处理机制
- .net错误处理机制
- .net错误处理机制
- QTP错误处理机制
- Windows 错误处理机制
- QTP错误处理机制
- net错误处理机制
- QTP错误处理机制
- C++学习---(二)
- golang实践-如何实现高性能的定时任务管理器
- Hibernate_Session核心方法
- ztree 带搜索框的 下拉选择树
- @Autowired与@Resource区别
- 错误处理机制跳转错误页面
- TensorFlow在图像识别中的应用
- PLSQL DDL Trigger
- JDK 1.7 java.io 源码学习之AutoCloseable接口和try-with-resources语法
- 自定义VIEW③Canvas
- Codeforces 165C Another Problem On Strings 尺取 Or 前缀和
- [c]一个简单的二叉树
- Python中的多线程MultiThread
- [C#]Log4net创建日志及简单扩展