Wednesday, February 26, 2014

ASP.NET cookies in Windows 7


In ASP.NET we create cookies using following code –
 
//add cookie
            HttpCookie ssoCookie = new HttpCookie("SSOCookie");
            ssoCookie.Value = loginMainControl.UserName;
            ssoCookie.Domain = “.mydomain.com";
            ssoCookie.Expires = DateTime.Now.AddMinutes(5);
            Response.Cookies.Add(ssoCookie); 

Now when we redirect, where are the cookies stored in Windows 7 created in ASP.NET?

Before this let’s understand the cookie type we create above. When we specify the Expiry for a cookie means we are creating persistent cookie. That means my cookie will expire only after provided time span and not on my browser close. If I close my browser the cookie will still exist.
If we don’t specify expiry while cookie creation means by default the cookie will be deleted on browser close. This cookie is called as session cookie. Session cookies are always stored in browsers memory and hence they cannot be viewed on physical folder on Windows 7.

Now let’s you have create persistent cookie then where is the location of cookies in windows 7?
Open Run window and type – “shell:cookie” (without quotes).


This will open the cookie location of Windows 7 as shown below –



The files you see are nothing but the cookies. For the security purpose in windows 7 and onwards randomization of cookie file names are performed because of which you can see [in screenshot] random names for various cookies stored in the above mentioned location. However they may be possibility of not finding cookie create by you in Asp.NET. To dig more, set visibility and protected files visibility to true as below.

Open folder Option menu as shown below –  




Select option “show hidden files, folder and drives” and uncheck the option “Hide protected operating system files”. This will show up another folder called as “Low”. Inside “Low” folder  your persistent cookie may reside. 


 


Hope this helps.

Cheers…

Happy Cookie!!!

No comments:

Post a Comment