Reputation: 973
I have asp.net web application in vb. When users login cookies gets created and it stores users id in cookies. Now when user logs out it should delete or remove cookies from browser but it's not happening. After log out only userid gets deleted from browser but cookies remains null which creating problem in application. Please help to delete that particular cookie.
Protected Sub logout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles logout.Click
Response.Cookies("chkusername").Expires = DateTime.Now.AddDays(-1)
Response.Redirect("order-form.aspx")
End Sub
To check cookies I used below code
Private Sub Online_Medicines_order_online_Default_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not HttpContext.Current.Request.Cookies("chkusername") Is Nothing Then
userID.Text = Request.Cookies("chkusername").Value
Else
userID.Text = "No user Found"
End If
End Sub
Upvotes: 0
Views: 136
Reputation: 7490
You are not adding expired cookie to Response
object.
HttpCookie cookie = Request.Cookies("chkusername");
cookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(cookie);
Upvotes: 1