如何通过Windows应用程序删除cookie? [英] How to delete cookie through windows application ?

查看:86
本文介绍了如何通过Windows应用程序删除cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个Windows应用程序。我做了一个删除cookie的代码。当我执行该函数但它没有从浏览器中删除cookie时,它在我的代码中显示空值。我的代码是



Hi,
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("http://dev.livestuff.com");
            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;
            }



我必须在此代码中更新以删除cookie?


What I have to update in this code to remove the cookie ?

推荐答案

请参阅 - HttpWebRequest.CookieContainer 属性 [ ^ ]。

Refer - HttpWebRequest.CookieContainer Property[^].
Quote:

CookieContainer null 默认情况下。您必须分配 CookieContainer 对象的属性,以便在中返回cookie Cookie 属性.110).aspx> HttpWebResponse 由 GetResponse 方法。

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);



因此,带下划线的代码将始终返回 null 。 br />


您应该使用 Response.Cookies 查看所有cookie。在该链接中,检查它是如何从响应读取cookie,而不是请求


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.


这篇关于如何通过Windows应用程序删除cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆