当前位置: 首页 > 新闻动态 > 软件编程

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

作者:用户投稿 浏览: 发布日期:2026-01-16
[导读]: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);
}
}
}
}
免责声明:转载请注明出处:http://m.lexweb.cn/news/822965.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!