Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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.

Posted

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:

<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:

// 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, http://www.websiteABC.com cannot read cookies written by http://www.websiteXYZ.com.

 

HTH

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...