Session variable lost in redirect

I am having a problem with loosing a session variable after I redirect to another page. Here is my code:

login.aspx:

if(sAuthorized != "-1" && sAuthorized != "-2")

{

Session["user"] = sAuthorized;

Response.Redirect("index.aspx");

}

index.aspx:
private void Page_Load(object sender, System.EventArgs e)

{

   CheckLogin();

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

   DataSet ds = SqlHelper.ExecuteDataset(DataAccessLayer.ULTConn(), "sp_get_users_courses",

   new SqlParameter("@user", SqlDbType.VarChar, 20).Value = sUserID);

   dgCourses.DataSource = ds;

   dgCourses.DataBind();

}

private void CheckLogin()

{

   if(Session["user"] == null)

   {

      //Response.Redirect("login.aspx");

   }

}

This works on my Windows XP Pro SP2 laptop without any problems, but when I upload it to my Windows 2003 Server I get the following error when it redirects to the index .aspx page:

 

Server Error in '/ULTOnlineTraining' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   ULTOnlineTraining.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\ultonlinetraining\index.aspx.cs:29
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750


Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET Version:1.1.4322.2300

Any help would greatly be appreciated.

0
apittman80
7/22/2005 7:26:06 PM
asp.net.state-management 8807 articles. 0 followers. Follow

6 Replies
1089 Views

Similar Articles

[PageSpeed] 0

What is line 29 of your code?
0
nick
7/26/2005 8:20:23 PM
This is line 29:

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

Thanks for the help.
0
apittman80
7/26/2005 8:26:41 PM
There doesnt seem to be anything wrong with that line of code. Do you have cookies enabled on your machine? Or have your session management set to be cookieless?


Nick
0
nick
7/26/2005 8:36:18 PM
That was it. I changed it to cookieless="true". Are there any drawbacks to using this method?
0
apittman80
7/26/2005 8:43:06 PM
Its easier to be spoofed. If I get your session ID, the information between (), I can be automatically logged in as you. Its an unlikely event, but it is possible. Its also less performant than using cookies. Hope this helps


Nick
0
nick
7/26/2005 9:29:08 PM
Thanks for the help.
0
apittman80
7/26/2005 9:42:47 PM
Reply:

Similar Artilces:

Session state lost when url is an redirect
Hi, I have a website (www.mysite1.com) and created a implementation of user validation (just a validate with database and save it into the session). The user data will be saved in Session, to make this information available through the application. This works fine. However, there exists also a website (www.mysite2.com), but this only a redirect to "mysite1". This redirect will keep the url of "mysite2" in the address bar. Now the part i don't get: When login through "mysite2" the userdata isn't persisted. Could anyone tell me why the second website give these problems? tx, RamR0m d...

Session variables lost after a redirect page
Hi all , I have encounter a session variable lost after a redirect page when i set the cookiesless=false in web.config. This happen when u i tried to access the asp.net application from another pc while my asp.net application reside in another web server. therefore in order to solve this problem i tried to change in the web.config file by setting the cookieless =true than it works. <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="true" timeout="20"/> how can i have this prob...

Session State variable missing after Redirect
When an error occurs, I set a session variable so that after redirecting to an error page, a detailed explanation can appear.  The variable (a string) is gone by the time I reach Page_Load in the target page.  I've checked and it is the same session ID. Any ideas? Are Sessions enabled? Are you forwarding to a page outside of you application?View My Blog Download My URL Rewriter and Reverse ProxyOnly $9.95/month, ASP.NET, 2GB & SQL 2005...

Session Variables lost after Response.Redirect()
Hi gurus,  I encouter lost session variables trouble when Response.Redirect() to another aspx page. I set 19 Session variables before redirecting. However, the redirected page's session contains only One variable. The very weir sympton is: If I restart IIS, only for the first IE encounter, the redirected page DOES show all 19 session variables.Once I close IE, any further IE or IE from any other machine's only shows ONE session variable. I can also reproduce such symptons in VS2005 development environment. Can someone tell me what I have missed?   Thanks! Here is ...

Query string and session variables lost after redirect
Hi, I'm trying to redirect a user form one application to another by using response.redirect(). I need to pass a returnURL so I'm doing this through a query string: In myapp1 I call: Response.redirect(http://localhost/myapp2/logon.aspx?ReturnUrl=http://www.mysite.com, true) When debugging the myapp2, in page_load of logon.aspx.cs I've lost the query string AND some session variables I stored. The session ID is the same.... Any idea? Any configuration to be set in web.config? Thanks a lot, Claudio...

State management upon session variable changes
I noticed that whenever a session variable is changed...the application knows about it and suddenly restarts session. My question is does restart "ALL" sessions or only the active sessions for which the variables changed? Imagine a "multi-user" application all with different states and an administration panel that lets you change session variables.  In this case, my question has to do with the question that if Company X changes his session variables, will only Company X's sessions be reset or will all "sessions" be reset?  Hope that makes sense. ...

Session variables vs. Session States
What is the difference and in what situations are they used. Thanks, Mattypee A session state (the state of your session) holds your session variables. If your session state expires (due to inactivity) then you lose your session variables...and any other info stored for that session. If you need to store USER specific information within a web app, then session variables are one(of several) ways to do it. MajorCatsMajorCats Is there any code that you could show that would give an example? Thanks, Mattypee example of what? reading and writing session variables? ...

Opinions on Viewstate vs. Session variable for state management on dataset
I came across many sample codes that using ViewState(myDataSet) and Session("myDataSet"). Which is a better way to use to keep the session around. What are the pros and cons? Anybody can share with your experience or thoughts? Thanks, teresa Take a loot at this article: State Management in Web Forms http://www.c-sharpcorner.com/Code/2004/Feb/StateManagementInWebForms.aspDarrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you!...

Lost session variables on redirect after cross-domain httppost request
Hi all, I have an asp page with an httppost request to bypass login for another .net page on another domain.  This works fine and returns the results as expected.  I am having difficulty when navigating away from the resulting page as the post request I have made is simply response.write of the xml returned so the page stays on the old domain without a redirect to the new site.  Therefore any links I have on the new page do not work without using the fullpath to the page, same goes for any buttons which do postback as the page does not exist...

Last variables stored in Session get lost when redirecting to _target page.
 We have a session object that holds certain data - on our last panel of our panel wizard we ask two questions: checkbox :  Use pre-printed paper?radioBox:  Most recent test                    All past tests we save those two variables to our session like several other variables that we have saved. This then Redirects to a _target page that builds our report.  HOWEVER, alot of the time (AND NOT ALWAYS) these last two variables do not get populated to our session?  If I debug and...

Session State Variables across multi sessions
I am having an issue where I save my DataTable into a Session Variable:   Session["dtDMFile"] = dtDMFile; Different users can use the web form that I created. Once the data is loaded,I send the DataTable to the session variable. My problem is that when I go to reload the data in the table, it is taking the data from the last user who stored the DataTable instead of from the particular user on their browser. For instance, User 1 (machine 1) loads data with field contents of: field1  field2  field3 User 2 (machine 2), then loads data with field contents of: f...

Session state lost every other session after conversion from 2003 to 2005
Hi, I have a weird problem here I can't really place. Maintaining session state was never a problem with VS2003 but after the conversion to VS2005 I have session state problems.I put a value in the session state in the !IsPostBack in Page_Load. After that if statement I take out that variable again just to test if it is in the session state. This goes ok for the first time I work with th e application. If I then close the browser and go to it again this fails. After the postback the webapplication doesn't enter the !IsPostBack if statement but the variable is also not in the Ses...

Loosing session state when I call a session variable from a derivated class
Hi folks I'm having an annoying problem. I have a web application which is used to edit some database data. The databases content may be in various languages, having one database for each language. I load a database calling it by the database name and the language suffix (for example: database_eng, when 'eng' is the laguage variable). So, I need to set a session variable 'Language', which is used in any webpage that calls information from a database. The problem I have is in some classes, which stores some methods to obtain information from databases. These clas...

When does Session.Abandon remove session variables (.NET 1.1)?
I have a logout function which includes session.abandon. This also (correctly) removes any session variables I've created if I look at them on the next page load. However, if I examine these variables immediately after the session.abandon call, they still exist with their current values. Where in the page life cycle does session.abandon actually remove these variables? Thanks in advance.  -- ZLA  After you have called Abandon() method, current session becomes invalid, but new session will be created on the next request. If you need to remove all values from session coll...

Web resources about - Session variable lost in redirect - asp.net.state-management

Variable - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Westpac interest rate rise is one of many variable loan rate rises
WESTPAC is not alone in hitting its owner-occupier customers with a surprise interest rate rise, as dozens of other variable rate home loans ...

Airbnb upgrades variable pricing tool for hosts
Online home rental group Airbnb is rolling out an upgraded variable pricing tool that automatically raises or cuts room rates based on supply ...

Commonwealth Bank raises variable home loan rates
Home owners' mortgage costs are set to rise by hundreds of dollars a year, after the Commonwealth Bank became the latest bank to hike interest ...

CBA lifts variable home loan rates to offset costs associated with stricter capital requirements
The Commonwealth Bank to lift its home loan interest rates independently of the Reserve Bank to partially offset costs associated with stricter ...

Washington Square Signs Spielbergs, Choi Joins Variable and More
... films and an episode of the HBO comedy series "Girls," on which he plays the role of Ray Ploshansky. New York-based creative collective Variable ...

YouTube v10.32 Tweaks Some Interface Elements And Includes Hints About Virtual Reality Content And Variable ...
Forget Update Wednesday! Monday is the new big day. Not only were we treated to the latest M preview release and the official Marshmallow name, ...

"You have to ignore many variables to think women are paid less than men. California is happy to try." ...
Writes Sarah Ketterer in The Wall Street Journal in "The ‘Wage Gap’ Myth That Won’t Die" (which you can get to without subscribing if you Google ...

Staley: 'A lot of different variables...been a hard year'
... 41° Navigation Home Giants A's Sharks Warriors Kings 49ers Raiders Quakes Insiders More Tickets Shop Watch Staley: 'A lot of different variables...been ...

Expert Reveals the Latest Variable Capacity Technology
Learn about gForce Ultra CRAC equipment, the latest variable capacity technology to lower energy usage and increase reliability.

Resources last updated: 1/3/2016 2:29:55 AM