我为我的ASP.NET 4应用程序制作了一个自定义错误页面。我将异常对象放入HttpContext.current.Session["CustomError"]
但当用户被重定向到错误页面时HttpContext.current.Session["CustomError"]
为null。我在 CustomError 类构造函数中这样做:
public CustomError(enExceptionType ExceptionType) : base(ExceptionMessage(ExceptionType)) {
HttpContext.Current.Session["CustomError"] = this;
}
当我跨过代码 Session["Error"] 包含错误对象时。任何的想法?
更新:
我从 web.config 中删除了自定义错误页面并将其添加到 glabal.asax:
void Application_Error(object sender, EventArgs e)
{
if (Context.IsCustomErrorEnabled)
{
Response.Redirect("~/Error.aspx");
}
}
通过逐步执行此函数,我注意到当抛出异常时,此函数被调用两次,第一次 Session["CustiomError"] 包含错误对象,但第二次为空。