void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
if (ex is HttpException)
{
if (((HttpException)(ex)).GetHttpCode() == 404)
Server.Transfer("~/Error404.aspx");
}
// Code that runs when an unhandled error occurs
Server.Transfer("~/DefaultError.aspx");
}
{
Exception ex = Server.GetLastError();
if (ex is HttpException)
{
if (((HttpException)(ex)).GetHttpCode() == 404)
Server.Transfer("~/Error404.aspx");
}
// Code that runs when an unhandled error occurs
Server.Transfer("~/DefaultError.aspx");
}
本文介绍了一段 ASP.NET 应用程序中的错误处理代码,该代码能够捕捉未处理的异常,并根据不同类型的错误进行页面跳转。对于 404 错误,将转向 Error404.aspx 页面;而对于其他所有类型的错误,则会转向 DefaultError.aspx 页面。

被折叠的 条评论
为什么被折叠?



