joe_pool_is Posted May 25, 2008 Posted May 25, 2008 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? Quote Avoid Sears Home Improvement
Administrators PlausiblyDamp Posted May 26, 2008 Administrators Posted May 26, 2008 Are the root folder and the sub-folder configured as different applications under IIS? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joe_pool_is Posted May 26, 2008 Author Posted May 26, 2008 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. Quote Avoid Sears Home Improvement
Nate Bross Posted May 27, 2008 Posted May 27, 2008 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 Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
joe_pool_is Posted May 27, 2008 Author Posted May 27, 2008 I don't know why I never thought of using Cookies before. That'd save a lot of headaches. Thanks for the idea, Nate! Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.