我为我的ASP.NET 4应用程序制作了自定义错误页面。我将异常对象放在HttpContext.current.Session["CustomError"]
中,但是当用户重定向到错误页面HttpContext.current.Session["CustomError"]
时是null。 我这样做是在CustomError类的构造函数是这样的:HttpContext.current.Session在错误中被清除页面
public CustomError(enExceptionType ExceptionType) : base(ExceptionMessage(ExceptionType)) {
HttpContext.Current.Session["CustomError"] = this;
}
当我迈过码会话[“错误”]包含错误的对象。 有什么想法?
UPDATE:
我删除了从web.config中的自定义错误页,并已将此添加glabal.asax:
void Application_Error(object sender, EventArgs e)
{
if (Context.IsCustomErrorEnabled)
{
Response.Redirect("~/Error.aspx");
}
}
通过这个功能我注意到,当一个异常被抛出此功能是步进称为两次,第一次Session [“CustiomError”]包含错误对象,但第二次为空。
要实现与自定义错误会话,如果你想记录它做什么,你可以使用我将不胜感激全局asax中的application_error事件 – Ivo 2011-04-23 08:46:00
我想在错误页面上显示自定义错误对象的错误信息。 – nima 2011-04-23 08:47:56
你可以把代码放在你指定异常的地方吗? – 2011-04-23 08:55:08