Session["UserName"]

J

John

Hi,

I use Session["UserName"] to save and pass values between pages, (please see
the following). It works fine on my computer, but on the server, I launch the
main page, wait for 20 minutes, and click a button to launch User.aspx, it
seems that it cannot see the current value of Session["UserName"]. There's no
problem to launch User.aspx from the main page within 20 minutes. Please
help. Thanks.

//Users.aspx
if (!Page.IsPostBack)
{
if (Convert.ToString(Session["UserName"]) != "")
{
//Do something
}
}
 
M

Mark Fitzpatrick

Also, the simples way of testing to see if a session variable exists is to
see if it's null or not. Converting it to a string first is a waste. Just do
if(Session["UserName"] != null)
{
Do Something
}

This also helps prevent errors from being thrown if you attempt to convert
upon a null object.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression
 

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

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top