All, I'm trying to implement an HttpModule (IHttpModule) to catch pages request and redirect to a new page. Unfortunately, it seems I can't use the Session
in the new page. because the Session
is null.
Here is my code looks like. please review it .
public class MyModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
....
HttpContext.Current.Server.Transfer("newpage.aspx");//redirect to new page.
}
}
In the newpage.aspx
, There is an exception says Object reference not set to an instance of an object
for the code HttpContext.Current.Session[xxx]
, Because the HttpContext.Current.Session
is null .
Could someone tell me what happen to it ?
Thanks.
Update
All, I found If I use the HttpContext.Current.Response.Redirect
to redirect url . Everything is ok. I mean the Session
object is initiated before being used.But that doesn't work for Server.Transfer
.
I already knew what is the difference of these two.