Session Variable Problems

joe_pool_is

Contributor
Joined
Jan 18, 2004
Messages
507
Location
Longview, TX [USA]
I'm declaring some session variables on one form, that are in a subdirectory.

They do not seem to be visible in the main directory whenever I redirect to them.

Am I missing something?

Session variables are not declared, are they? I'm trying to port over some old Classic ASP code to C#, and I am declaring them similar to before:

Session["value1"] = txtValue1.Text;

Whenever I get to my other form, however, Session["value1"] does not exist.

What's "the way" to do this?
 
Probably. (as far as I know)

Each page is its own creature, if that's what you mean. The only reason one page has any idea about the other is because upon successful cranking through the code, it calls Response.Redirect to the page in the root folder.

I'm hosting on GoDaddy. I know they are not the best, and they won't offer any support with this type of problem. But, I'm stuck using them for now.

The older Classic ASP forms held the Session objects in a global way. I could set the values in a form running in one folder and they would be visible in other folders.

Any thoughts on how to recreate this without going back to Classic ASP?

I realize redesigning the entire website so that each piece of it looks to a global web.config file would probably be great, but that would take time that isn't avaiable at the moment.

We just want the contact form to start working again.
 
You should find out which type of session's are used on your IIS server from GODaddy. If they are using the iis worker process the session variables will not be maintained across Virtual Directories, and will "randomly dissapear." If they enable "SessionState" you can use these steps to setup the "ASP.NET State Service"

Go to Start >> Run >> Services.msc find the “ASP.NET State Service” go to Properties and start. (for servers, change startup type to "automatic")

Also drop this in your Web.config:
Code:
<sessionState
      mode="StateServer"
      stateConnectionString="tcpip=127.0.0.1:42424"
      cookieless="false"
      timeout="20" />

This will help maintain more reliable session variables. Since we cannot see the actual deployment (Virtual Directories) its hard to say if this will fix your problem or not.

However, depending on the complexity (and size) of the data you are putting into session variables, you might be better off using Cookies:
Code:
// set cookie
Response.Cookies.Add(new HttpCookie("MyCookie", "MyValue"));
Response.Cookies["MyCookie"].Expires = DateTime.Now.AddDays(5);

// get cookie
Response.Cookies["MyCookie"]


Cookies must be < 4096 Bytes, and can only be read by pages in the same domain as they were set. For example, www.websiteABC.com cannot read cookies written by www.websiteXYZ.com.

HTH
 
Back
Top