请参阅下面的代码
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:对象引用没有设置为对象的实例。
发布于 2013-08-22 13:29:41
您正在请求BeginRequest中的会话状态,该状态在应用程序生命周期中会话状态可用之前。至少,在AcquireRequestState事件之前,您不能使用会话状态。
更改Init以处理AcquireRequestState而不是BeginRequest。
https://stackoverflow.com/questions/18381576
复制相似问题