asp.net: moving from session variables to cookies

Posted by P a u l on Stack Overflow See other posts from Stack Overflow or by P a u l
Published on 2009-01-13T08:48:17Z Indexed on 2010/03/16 9:56 UTC
Read the original article Hit count: 166

Filed under:

My forms are losing session variables on shared hosting very quickly (webhost4life), and I think I want to replace them with cookies. Does the following look reasonable for tracking an ID from form to form:

if(Request.Cookies["currentForm"] == null)
   return;
projectID = new Guid(Request.Cookies["currentForm"]["selectedProjectID"]);
Response.Cookies["currentForm"]["selectedProjectID"] = Request.Cookies["currentForm"]["selectedProjectID"];

Note that I am setting the Response cookie in all the forms after I read the Request cookie. Is this necessary? Do the Request cookies copy to the Response automatically?

I'm setting no properties on the cookies and create them this way:

Response.Cookies["currentForm"]["selectedProjectID"] = someGuid.ToString();

The intention is that these are temporary header cookies, not persisted on the client any longer than the browser session. I ask this since I don't often write websites.

© Stack Overflow or respective owner

Related posts about ASP.NET