服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - ASP.NET教程 - asp.net 在global中拦截404错误的实现方法

asp.net 在global中拦截404错误的实现方法

2019-07-15 10:04ASP.NET之家 ASP.NET教程

asp.net 在global中拦截404错误,增加用于体验,不会因为提示找不到信息而直接退出的尴尬。

代码如下:


void Application_Error(object sender, EventArgs e) 

if(Context != null) 

HttpContext ctx = HttpContext.Current; 
Exception ex = ctx.Server.GetLastError(); 
HttpException ev = ex as HttpException; 
if(ev!= null) 

if(ev.GetHttpCode() == 404) 

ctx.ClearError(); 
Response.Redirect("~/nofound.aspx", false); 
Response.End(); 

else 

Server.Transfer("~/Error.aspx", false); 



}

延伸 · 阅读

精彩推荐