asp.net 在global中攔截404錯誤的實現(xiàn)方法
更新時間:2010年03月05日 18:05:31 作者:
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);
}
}
}
}
您可能感興趣的文章:
相關文章
ASP.NET中實現(xiàn)定制自己的委托和事件參數(shù)類
這篇文章主要介紹了ASP.NET中實現(xiàn)定制自己的委托和事件參數(shù)類,需要的朋友可以參考下2014-08-08
DataGridView使用自定義控件實現(xiàn)簡單分頁功能(推薦)
這篇文章主要介紹了DataGridView使用自定義控件實現(xiàn)簡單分頁功能,數(shù)據(jù)庫使用的是sqlserver,本文通過通過實例代碼給大家講解的非常詳細,需要的朋友參考下吧2019-11-11

