Search code examples
asp.netsessionweb-configsession-variablesresponse.redirect

Session variable not maintained on Response.Redirect


I have a login page and i am redirecting to another page on login. I am saving some data in Session, but unable to retrive the same in Page2.aspx.

I found some blogs and sites stating the same issue, but their solution won't work.

Here is my code from Page1.aspx

Session["Username"] = name; Response.Redirect("~/Page2.aspx",false);

In Page2.aspx

 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["Username"] != null)
         ClientScript.RegisterStartupScript(GetType(), "", "sendtoken();", true);
     else
         Response.Redirect("Page1.aspx");                 
}

Here the Session["Username"] is null

n the code in web.config is simple. I tried using

sessionState timeout="2"

n

mode="InProc" and "StateServer"


Solution

  • The most common cause is cookies being disabled. You'll need to require cookies, or switch to a cookieless session model, which is a little harder to work with. refer this

    http://support.microsoft.com/default.aspx?scid=kb;EN-US;q316112