I am sending a HTTPWebRequest from C# code and in response I am getting a cookie containing session ID. I am not able to locate the cookie in the public/non public members of response. However fiddler is capturing the cookie and its path is "/". Can anyone please tell me where should I look for this cookie? I have checked the folder "C:\Users\UserName\AppData\Roaming\Microsoft\Windows\Cookies" and its not there.
4 Answers
Cookies may be physically stored in different locations, depending on the browser.
I think you're better off getting the HttpWebRequest
working with cookies.
See the answer to this question regarding adding a CookieContainer
to the request object.
Every browser store cookies onto different locations For example
Cookie information is stored in the profile folder, in two files. Starting with Firefox 3.0 and SeaMonkey 2.0 the cookie information is stored in the files cookies.sqlite and permissions.sqlite. In Firefox 2 or below and Mozilla Suite/SeaMonkey 1.x, cookies are stored in the cookies.txt file and cookie site permissions are stored in the hostperm.1 file. File Description cookies.sqlite cookies.txt Holds all of your cookies, including login information, session data, and preferences. permissions.sqlite hostperm.1 Holds preferences about which sites you allow or prohibit to set cookies, to display images, to open popup windows and to initiate extensions installation.

- 29,419
- 9
- 72
- 100
Cookie storage depends on both your browser and OS. In older browsers, they were just stored in a file path named something like "Cookies". Most modern browsers store cookies in some encrypted way, usually in a sqllite db flat file. If you could provide more info on what you are trying to track down via the actual local cookie storage (as opposed to using the browser's built in cookie browser), it would help get more info on where to look or alternatives for what you have in mind.

- 36,459
- 25
- 97
- 163
If you want to use persistent cookies with HttpWebRequest, you'll need to import wininet.dll to handle this (or you handle persistence yourself).
There's an example on MSDN in the Community Content section for WebRequest.Create Method.
snippet
[DllImport("wininet.dll", CharSet=CharSet.Auto , SetLastError=true)]
private static extern bool InternetGetCookie (string url, string name, StringBuilder data, ref int dataSize);
private static string RetrieveIECookiesForUrl(string url)
{
StringBuilder cookieHeader = new StringBuilder(new String(' ', 256), 256);
int datasize = cookieHeader.Length;
if (!InternetGetCookie(url, null, cookieHeader, ref datasize))
{
if (datasize < 0)
return String.Empty;
cookieHeader = new StringBuilder(datasize); // resize with new datasize
InternetGetCookie(url, null, cookieHeader, ref datasize);
}
// result is like this: "KEY=Value; KEY2=what ever"
return cookieHeader.ToString();
}

- 17,626
- 12
- 64
- 115