如何通过c#编码清除存储在cookie中的数据. [英] How to clear the data stored in cookies through c# coding.

查看:98
本文介绍了如何通过c#编码清除存储在cookie中的数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

谁能告诉我如何通过c#编码清除cookie中存储的数据.

我正在尝试刷新asp.net页的服务器控件.

Hi all,

Can any one please tell me how to clear the data stored in cookies through c# coding.

I am trying to refresh the server controls of asp.net page.

推荐答案

Response.Cookies.Clear()使用此实现从响应中清除所有cookie.
Response.Cookies.Clear() use this implementation to clear all the cookies from the response.


信不信由你,Response.Cookies.Clear() 不是从Response删除cookie的可靠方法.为了可靠地从浏览器中删除cookie,您需要按照以下步骤设置cookie的到期时间:

Believe it or not, Response.Cookies.Clear() is not a reliable way to remove cookie from the Response. To remove the cookie from browser reliably, you need to set the expiry time of the cookie as follows:

/// <summary>
/// Removes Cookie from the response
/// </summary>
/// <param name="Cookie"></param>
private void RemoveCookie(HttpCookie Cookie)
{
    //Cookie is the current cookie that is to be removed.
    Response.Cookies.Remove(Cookie.Name);
    HttpCookie myCookie = new HttpCookie(Cookie.Name);
    myCookie.Expires = DateTime.Now.AddDays(-1d);
    Response.Cookies.Add(myCookie);
}


您尝试了 [
Did you try this[^]?

Google is an amazing search engine and very easy to use.
Learn using it and you will save yourself a lot of time and trouble. :)


这篇关于如何通过c#编码清除存储在cookie中的数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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