Session returns null

  • Thread starter Thread starter Maziar Aflatoun
  • Start date Start date
M

Maziar Aflatoun

Hi,

I'm writing a second user login for our website. I have a login page which
sets a session value and redirects the user back.

I have the following in the login page.

Session["UserID"]=UserID;
Session.Add("isAuthenticated",true);
System.Diagnostics.Debug.WriteLine("UserID:"+
Session["UserID"].ToString()); // works
Response.Redirect(ReturnURL);


However, in the return page the value becomes null
try
{
Response.Write("isAuthenticated:" + Session["UserID"].ToString() +
"<br>");
}
catch
{
Response.Write("isAuthenticated is empty<br>");
}

Any suggestions?

Thanks
Maz
 
Hi,

Do you use a cookie-based session? Does the client system has cookies
enabled?
 
Maziar,

Do you have the session state turned on in the web.config file for the
app?
 
Yes, it works for other parts of the application. Just this part.

Thanks
Maz.

Nicholas Paldino said:
Maziar,

Do you have the session state turned on in the web.config file for the
app?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Maziar Aflatoun said:
Hi,

I'm writing a second user login for our website. I have a login page
which
sets a session value and redirects the user back.

I have the following in the login page.

Session["UserID"]=UserID;
Session.Add("isAuthenticated",true);
System.Diagnostics.Debug.WriteLine("UserID:"+
Session["UserID"].ToString()); // works
Response.Redirect(ReturnURL);


However, in the return page the value becomes null
try
{
Response.Write("isAuthenticated:" + Session["UserID"].ToString() +
"<br>");
}
catch
{
Response.Write("isAuthenticated is empty<br>");
}

Any suggestions?

Thanks
Maz
 
BTW, if I remove Response.Redirect(ReturnURL) line and go to the requested
page directly by typing it in my browser, it works fine. So I guess it's the
response.redirect that's causing it. Any idea?
 
Maziar,

¿The return URL points to a page that belongs to the same application than
the current page?

Regards - Octavio

Maziar Aflatoun said:
BTW, if I remove Response.Redirect(ReturnURL) line and go to the
requested page directly by typing it in my browser, it works fine. So I
guess it's the response.redirect that's causing it. Any idea?


Maziar Aflatoun said:
Hi,

I'm writing a second user login for our website. I have a login page
which
sets a session value and redirects the user back.

I have the following in the login page.

Session["UserID"]=UserID;
Session.Add("isAuthenticated",true);
System.Diagnostics.Debug.WriteLine("UserID:"+
Session["UserID"].ToString()); // works
Response.Redirect(ReturnURL);


However, in the return page the value becomes null
try
{
Response.Write("isAuthenticated:" + Session["UserID"].ToString() +
"<br>");
}
catch
{
Response.Write("isAuthenticated is empty<br>");
}

Any suggestions?

Thanks
Maz
 
Back
Top