Session["UserName"]
am 14.04.2008 17:09:00 von 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
}
}
Re: Session["UserName"]
am 14.04.2008 17:39:43 von mark
"John" wrote in message
news:C609B973-6B56-4417-9CB3-5C2225ABDB69@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&i e=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=1I 7GGIH
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Re: Session["UserName"]
am 14.04.2008 18:18:15 von 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
"John" wrote in message
news:C609B973-6B56-4417-9CB3-5C2225ABDB69@microsoft.com...
> 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
> }
> }
>
Re: Session["UserName"]
am 14.04.2008 21:22:28 von Patrice
And managing the user is really a no-brainer when using ASP.NET 2.0
"John" wrote in message
news:C609B973-6B56-4417-9CB3-5C2225ABDB69@microsoft.com...
> 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
> }
> }
>