Session returns null

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
 
D

Dmytro Lapshyn [MVP]

Hi,

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

Nicholas Paldino [.NET/C# MVP]

Maziar,

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

Maziar Aflatoun

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
 
M

Maziar Aflatoun

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?
 
O

Octavio Hernandez

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top