473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Session Variables Object Lost On Redirect

Frinavale
9,735 Expert Mod 8TB
I currently have a website that collects information (mainly text and integers) inputed by users and stores that information into an object which is in turn stored in Session. Each page has its own object and each object knows if it is valid or not.

Everytime the user advances to the next page it checks to see if all of the data collected up to this point is valid by checking the objects which are stored in Session.

If the object is missing or if the data is invalid the user is redirected back to the page where the error was made.

Now here's the problem....when I redirect them back to the page they came from because the object contains invalid data, the object is no longer there.

I have no idea why this happens but I would like to redisplay the data on the screen (with error messages) when the user is redirected back but I cannot do this because somehow the objects no longer exist.

Has anyone got any thoughts on why this might be?
Oct 13 '06 #1
4 8537
Post some code, it sounds like your just not putting it into the session correctly. I have had some problems with this and found it easiest to pass my information to a page that its only purpose is to create the sessions.

Basically I don't load my sessions on the same page as my information.

Justin
Oct 18 '06 #2
Frinavale
9,735 Expert Mod 8TB
I'm starting to think that the reason I lose my session variables is because when the user types in the url of the page a new session is created and so my variables are lost. I don't know if I'm correct or not, but it does seem weird that on the page that they type the objects are there, and then when they are redirected (after putting all the objects into session) the objects are lost.

Here is some snipets of my code on the page that the user is redirected to.
************************************************** *****************************************

Expand|Select|Wrap|Line Numbers
  1. Private Sub GetAllObjectsFromSession()
  2.         'Getting all objects from session
  3.         page1Info= CType(Session("page1Info"), FirstPageInfo)
  4.         page2Info = CType(Session("page2Info"), SecondPageInfo)
  5.         page3Info = CType(Session("page3Info"), ThirdPageInfo)
  6. End Sub
  7.     Private Sub GetAllObjectsFromSession()
  8.         'Getting all objects from session
  9.         Session("page1Info") =page1Info
  10.         Session("page2Info") =page2Info 
  11.         Session("page3Info") =page3Info 
  12. End Sub
  13.  
  14.  
  15.  
  16.  
  17. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  18.  
  19.         GetAllObjectsFromSession()
  20.         If IsPostBack Then
  21.             'there is some code here but will be confusing so I'm not going to post it
  22.        Else
  23.        'clearing the errors, and filling in the information supplied earlier
  24.                        Try
  25.                             clearErrors()
  26.  
  27.                             'checking if the objects are valid and if not displaying approriate errors
  28.                             If Not page1Info.IsValid()Then
  29.                                 displayErrors()
  30.                             End If
  31.                         Catch ex2 As Exception
  32.                             page1Info= New FirstPageInfo
  33.                             PutAllObjectsIntoSession()
  34.                         End Try
  35.             End If
  36.  
Oct 23 '06 #3
scripto
143 100+
Couple of things

1. Session variables work only when you allow cookies, so make sure accept cookies is turned on.

2. If you use Response.Redirect() in .NET, you will have problems with Session vars. Instead use either
Response.Redirsct("nextpage.aspx", false) or
Server.Transfer()

hope this helps.
Oct 24 '06 #4
Frinavale
9,735 Expert Mod 8TB
Couple of things

1. Session variables work only when you allow cookies, so make sure accept cookies is turned on.

2. If you use Response.Redirect() in .NET, you will have problems with Session vars. Instead use either
Response.Redirsct("nextpage.aspx", false) or
Server.Transfer()

hope this helps.
I have tried Server.Transfer before but ran into an interesting issue and read about a few problems that happen when you have presistant data...

When I tried Server.Transfer the first page wrote to the Response buffer and then when we were directed (with server.transfer) to the second page that page's content was then appended to the first page's content. This would effectivly show 2 pages on one page.

I couldn't figure out how to flush the buffer just before the new content was written so I changed back to Response.Redirect.

I've never heard of Response.Redirsct("nextpage.aspx", false) so I will look it up and see if it helps. Thanks alot!
Oct 24 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Alex | last post by:
Thank you in advance. My ASP page 1 redirect user to third party's website, after the process at third party is finished, in 3rd party's page, there is one link to route user back to my...
9
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
14
by: Michael Carr | last post by:
I have an intermittent problem that occurs on a very small number of browsers that access my website. The strange thing is this: my site works perfectly for 99.9% of browsers. The behavior...
3
by: William | last post by:
Hi I have an ASP.NET application that connects to an Access database. Everything works fine except for the Session object. Data in the session object is lost after I've made a call to the...
3
by: catweezle2010 | last post by:
Hello NG, I have three files (default.aspx, search.aspx and work.aspx). The way is: login on default (if session is newsession). The loginname I write into as sessionvariable (username). So I...
7
by: Erik | last post by:
I have an application that uses sessions variables a lot but one I publish the application on the prod server these variables are lost. The application is written i c# 2.0 and I've set the...
0
by: Dornel | last post by:
Hi all, My session variables are lost when I using response.redirect at first time... In the second time, the problem not exists. example in page 1(create session and redirect): ...
2
by: Ned Balzer | last post by:
Hi, Apologies if this is a newbie question, I haven't found the answer in any faqs. I have an asp.net 2.0 page that sets session variables and then redirects to another page. For the page...
22
by: K. A. | last post by:
I have two servers at work, 'A' for testing and development, and server 'B' for production. On server A, I wrote a PHP test code to login users then direct them to a personalized page. This is...
14
by: Rick | last post by:
We are in the process of testing a large web project that I converted from VS 2003 to VS 2005. Everything seems to be working except for a few minor things. But the main issue I have is this, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.