Loosing session variables in redirect

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am developing my web apps on a Win XP Pro SP2 laptop and then uploading
them to a Windows Server 2003. My current project involves using session
state variables to keep track of user after they have logged in. The
login.aspx page contains the following code:

if(sAuthorized != "-1" && sAuthorized != "-2")
{
Session["user"] = sAuthorized;
Response.Redirect("index.aspx");
}

Then the index.aspx page contains the following code in the page load event:

string sUserID = Session["user"].ToString();

Now, everything works fine on my laptop, but when I try to run it on the
server I get an "Object reference not set to an instance of an object" error
when it tries to set sUserID equal to the session variable. Any suggestions
would greatly be appreciated. Thanks.
 
I suppse that condition is never met, so to go over this problem add just for
a test an else clausule and assign something to session["user"] variable.
Then, read on the redirected page once again this value.
 
Of course I assume, that you have cookies enabled in Browser and Session
State is enabled on server machine...
 
Back
Top