asp.net mvc - Remove cookie by expiring it not working -


i have cookie add response, if cookie same key exists want remove otherwise end 2 cookies of same key.

i thought expiring cookie remove browser?

httpcookie cookie = new httpcookie("usercookie"); cookie.value = encticket;  if (httpcontext.current.request.cookies["usercookie"] != null)     clearcookie("usercookie");  httpcontext.current.response.cookies.add(cookie);   private static void clearcookie(string key) {     var httpcontext = new httpcontextwrapper(httpcontext.current);     var _response = httpcontext.response;      httpcookie cookie = new httpcookie(key)     {         expires = datetime.now.addmonths(-1),         value = null     };      _response.cookies.add(cookie); } 

any appreciated.

"you cannot directly delete cookie on user's computer. however, can direct user's browser delete cookie setting cookie's expiration date past date. next time user makes request page within domain or path set cookie, browser determine cookie has expired , remove it."

please read following article more detail.

http://msdn.microsoft.com/en-us/library/ms178195(v=vs.85).aspx


Comments