Click here to Skip to main content
15,936,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an windows application.I did a code to delete the cookie. It is showing null value in my code when I execute the function but its not deleting cookie from i.e. browser. My code is

System.Net.HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("");
            Request.CookieContainer = new CookieContainer();
            HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
            Response.Cookies = Request.CookieContainer.GetCookies(Request.RequestUri);

            if (Response.Cookies["fVersion"] != null)
               Response.Cookies["fVersion"].Value = string.Empty;

What I have to update in this code to remove the cookie ?
Updated 11-Jun-14 21:46pm

1 solution

Refer - HttpWebRequest.CookieContainer Property[^].

CookieContainer is null by default. You must assign a CookieContainer object to the property to have cookies returned in the Cookies property of the HttpWebResponse returned by the GetResponse method.

Response.Cookies = Request.CookieContainer.GetCookies(Request.RequestUri);

So, the underlined code would return you null always.

You should use Response.Cookies to see all the cookies. In that link, check how it is reading the cookies from response, not request.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900