如何在Session_End事件中删除所有应用程序cookie [英] How to delete all application cookie in Session_End event

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

问题描述

我在VB.Net和ASP.Net上有一个Web应用程序。

任何人都可以帮我删除Session_End事件中的所有cookie吗?

因为我注意到HttpContext.Current.Response.Cookies返回对象引用

issue。

I have a web application in VB.Net & ASP.Net.
Can any one help me to delete all cookie's in Session_End event ?
Since i have noticed that HttpContext.Current.Response.Cookies return object reference
issue.

推荐答案

C#


C#
string subkeyName;
subkeyName = "userName";
HttpCookie aCookie = Request.Cookies["userInfo"];
aCookie.Values.Remove(subkeyName);
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);







VB






VB

Dim subkeyName As String
subkeyName = "userName"
Dim aCookie As HttpCookie = Request.Cookies("userInfo")
aCookie.Values.Remove(subkeyName)
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)







来源msdn网站:)




Source msdn site :)


试试这个.. :)



try this.. :)

void Session_End(object sender, EventArgs e) 
    {
       HttpCookie aCookie;
string cookieName;
int limit = Request.Cookies.Count;
for (int i=0; i<limit; i++)
{
    cookieName = Request.Cookies[i].Name;
    aCookie = new HttpCookie(cookieName);
    aCookie.Expires = DateTime.Now.AddDays(-1);
    Response.Cookies.Add(aCookie);
}
    }





+>>>>>>>>> <<<<<<< //forums.asp.net/t/1414071.aspx?How+do+i+remove+all+cookies+in+c+and+signout+completelytarget =_ blanktitle =New Window> ^ ]



在Global.asax中清除Cookie值

[ ^ ]



ASP.NET Cookie概述 [ ^ ]



How do i remove all cookies in c# and signout completely[^]

Clear Cookie Value in Global.asax
[^]

ASP.NET Cookies Overview[^]


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

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