Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Session["UserName"]

0 views
Skip to first unread message

John

unread,
Apr 14, 2008, 11:09:00 AM4/14/08
to
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
}
}

Mark Rae [MVP]

unread,
Apr 14, 2008, 11:39:43 AM4/14/08
to
"John" <Jo...@discussions.microsoft.com> wrote in message
news:C609B973-6B56-4417...@microsoft.com...

> 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.

20 minutes is the default time that a session exists before it is torn down
to conserve server resources.

Either increase the session timeout value,
http://www.google.co.uk/search?sourceid=navclient&hl=en-GB&ie=UTF-8&rlz=1T4GZEZ_en-GBGB252GB252&q=Session%2eTimeout

or change your logic...
http://www.google.com/search?q=Session.IsNewSession&rls=com.microsoft:*:IE-Address&ie=UTF-8&oe=UTF-8&sourceid=ie7&rlz=1I7GGIH


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mark Fitzpatrick

unread,
Apr 14, 2008, 12:18:15 PM4/14/08
to
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

"John" <Jo...@discussions.microsoft.com> wrote in message
news:C609B973-6B56-4417...@microsoft.com...

clintonG

unread,
Apr 14, 2008, 3:22:28 PM4/14/08
to
And managing the user is really a no-brainer when using ASP.NET 2.0


"John" <Jo...@discussions.microsoft.com> wrote in message
news:C609B973-6B56-4417...@microsoft.com...

0 new messages