How to read cookies in Winforms


I have Windows Application in which i want to read cookie set in the browser i am also attaching my code with question.

What i am doing I am creating Windows user control which i place in ASP.Net application which read a cookie value from the client machine. But The User Control Display in the ASP.Net application can't read the cookie value. I am also attaching code which i am using in User Control ,

textBox1.Text = "Hello";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("");

//Uncomment the following statements to set up proxy, if have
//request.Proxy = new System.Net.WebProxy("http://yourproxyservername: portnumber");
//request.Proxy.Credentials = CredentialCache.DefaultCredentials;

//Define an empty CookieContainer class object
//before the HTTP request is sent
request.CookieContainer = new CookieContainer();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

//Assign the Cookie property of the HttpWebResponse object to the original
//CookieContainer object in the HttpWebRequest object
response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
foreach (Cookie cky in response.Cookies)
Console.WriteLine(cky.Name + " = " + cky.Value);
MessageBox.Show(cky.Name + " = " + cky.Value);

Does any one have any idea about this?.. Please help

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!