Using MVC
I am creating a cookie on login like the following:
Response.Cookies.Add(New HttpCookie("UserId", Id))
I searched for ways to delete cookies so I can use it on Logout, and I found this:
If Response.Cookies("UserId") IsNot Nothing Then
Dim c = New HttpCookie("UserId")
c.Expires = DateTime.Now.AddDays(-1)
Response.Cookies.Add(c)
End If
Response.Cookies.Clear()
And on Client side I am doing the following:
document.cookie = "access_token=";
But I figured out this doesn't delete the cookie, it just empties it, I would still have a cookie called UserId
with a value of Nothing
.
Now if the user Logs out and logs in right after it, it's causing me problems.
What I want to do, is completely delete the Cookie with the name UserId
, Completely erase it from the browser cookies, not just empty its value.
Is there any way to do that?
Edit
I think the problem is with this part:
If Response.Cookies("UserId") IsNot Nothing Then
Dim c = New HttpCookie("UserId")
Because when I debug this code, after this line, The count of Response.Cookies I get is 2 , means it's creating 2 cookies with the same name and getting confused.