真的隐藏我也找不到方法,只是通过global.asax 实现
public class PageError
{
public static void Page_Error()
{
Exception objErr = System.Web.HttpContext.Current.Server.GetLastError();
//404 页面处理,同理其它页面也可以这样设置 也可以通过iis设置(ASP.NET 伪静态 静态页 访问不了 方法http://yfdong21.iteye.com/blog/856656)
if (objErr.GetType().Name.Equals("HttpException"))
{
System.Web.HttpException httpex = (System.Web.HttpException)objErr;
int httpcode = httpex.GetHttpCode();
if (httpcode == 404)
{
System.Web.HttpContext.Current.Response.Redirect("~/404.html");
return;
}
}
//错误内容
string err = "<b>Error Caught in Page_Error event</b><hr><br>" +
"<br><b>Error in:</b>" + System.Web.HttpContext.Current.Request.Url.ToString() +
"<br><b>Error Message:</b>" + objErr.Message.ToString() +
"<br><b>Stack Trace:</b><br>" +
objErr.StackTrace.ToString();
System.Web.HttpContext.Current.Response.Write(err.ToString());
//记录到日志 日志属性:http://msdn.microsoft.com/zh-cn/library/system.diagnostics.eventlog_members(v=VS.80).aspx http://wenku.baidu.com/view/07a6361ec5da50e2524d7ff5.html
//System.Diagnostics.EventLog e = new System.Diagnostics.EventLog();
//e.Log = "yfdong21"+DateTime.Now.ToString();
//e.MachineName = "ts";
//e.Source = "MySource ";
//e.WriteEntry(err);
System.Web.HttpContext.Current.Server.ClearError();
//错误页跳转
System.Web.HttpContext.Current.Response.Redirect("~/errorinfo.html");
}
}