请参阅下面的代码如何处理IHttpModule中的会话?
public class URLRewriter : IHttpModule {
public void Dispose() {
}
public void Init(HttpApplication context) {
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e) {
//code to make custom
URLhttpApplication.Context.Server.Transfer(CustomPath);
}
}
这里我使用IHttpModule
制作自定义URL重定向。但它在目标页面中设置会话时显示错误。
错误行代码:
HttpContext.Current.Session[USERADMIN] == null
错误消息:
System.NullReferenceException:未设置为一个对象的一个实例 对象引用。
检查此其他帖子: [1]:http://stackoverflow.com/questions/276355/can-i-access-session-state-from-an-httpmodule –