asp.net 在global中攔截404錯誤的實現方法
來源:懂視網
責編:小采
時間:2020-11-27 22:43:31
asp.net 在global中攔截404錯誤的實現方法
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
導讀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

代碼如下:
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);
}
}
}
}
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
asp.net 在global中攔截404錯誤的實現方法
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