【发布时间】:2009-05-15 16:05:49
【问题描述】:
是否可以在 404 之后的 HttpModule 的错误事件处理程序中访问 SessionState?
我正在尝试使用此博客文章中描述的技术为完整和部分回发实现一致的错误处理机制,
我试图将异常推送到会话状态并从错误页面访问它,而不是在查询字符串上传递大量参数。
在我执行 Server.Transfer(在 HttpModule 的错误处理程序中)时,SessionState 永远不可用,因此对错误页面不可用。
我尝试了将 IHttpHandler 重置为具有 IRequestSessionState 接口的技巧,但没有任何乐趣。
提前致谢,
编辑 - IHttpModule 错误处理程序的代码是,
void context_Error(object sender, EventArgs e)
{
try
{
var srcPageUrl = HttpContext.Current.Request.Url.ToString();
// If the error comes our handler we retrieve the query string
if (srcPageUrl.Contains(NO_PAGE_STR))
{
// Deliberate 404 from page error handler so transfer to error page
// SESSION NOT AVAILABLE !!!!
HttpContext.Current.ClearError();
HttpContext.Current.Server.Transfer(string.Format("{0}?ErrorKey={1}", ERROR_PAGE_URL, errorKey), true);
}
else
HttpContext.Current.Server.ClearError();
return;
}
catch (Exception ex)
{
Logging.LogEvent(ex);
}
}
马特
【问题讨论】: