如何在C#中删除类文件中的HttpCookie对象值 [英] How to delete HttpCookie object value in class file in C#
本文介绍了如何在C#中删除类文件中的HttpCookie对象值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我分配如下的cookie
I assign a cookie like below
string sKey = txtUName.Text + txtPwd.Text;
HttpCookie uidpwd = new HttpCookie("uidpwd");
uidpwd.Value = sKey;
Response.Cookies.Add(uidpwd);
所以想在类文件中删除它,如下所示
so want to delete it in class file like below
HttpContext.Current.Request.Cookies["uidpwd"].Expires = DateTime.Now.AddSeconds(1);
但是抛出错误对象引用没有设置为对象的实例
but throwing an error " Object reference not set to an instance of an object"
推荐答案
我google了asp.net删除cookie,这是第一个结果
https://msdn.microsoft.com/en-us/library/ms178195(v = vs.140).aspx [ ^ ]
I googled "asp.net delete cookie" and this was the first result
https://msdn.microsoft.com/en-us/library/ms178195(v=vs.140).aspx[^]
这篇关于如何在C#中删除类文件中的HttpCookie对象值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文