How do you clear cookies using asp.net mvc 3 and c#?

前端 未结 3 888
攒了一身酷
攒了一身酷 2020-11-29 02:56

Ok, so I really think I am doing this right, but the cookies aren\'t being cleared.

 Session.Clear();
 HttpCookie c = Request.Cookies[\"MyCookie\"];
 if (c !         


        
3条回答
  •  北海茫月
    2020-11-29 03:13

    Cookies are stored on the client, not on the server, so Session.Clear won't affect them. Also, Request.Cookies is populated by IIS and given to your page with each request for a page; adding/removing a cookie from that collection does nothing.

    Try performing a similar action against Response.Cookies. That should cause your client to overwrite the old cookie with the new one, causing it to be expired.

提交回复
热议问题