Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 12-Jun-14 19:31pm
v2
Comments
KaushalJB 13-Jun-14 2:47am    
What is the expire time you given in myCookie.Expires = ?
Mukesh Ghosh 13-Jun-14 3:37am    
Here is my code
HttpContext.Current.Response.Cookies.Clear()
HttpContext.Current.Response.Cookies("isLoggedInAs").Expires = DateTime.Now.AddYears(-30)
HttpContext.Current.Response.Cookies("DomainControl").Expires = DateTime.Now.AddYears(-30)

But, it say null for HttpContext.Current.Response

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)



Source msdn site :)
 
Share this answer
 
v2
try this.. :)

C#
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);
}
    }


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

Clear Cookie Value in Global.asax
[^]

ASP.NET Cookies Overview[^]
 
Share this answer
 
v2

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