Reputation: 13
I'm using following code for log out:
FormsAuthentication.SignOut();
Session.Abandon();
FormsAuthentication.RedirectToLoginPage();
the above code is working fine when I'm accessing my application from my pc. but if I hit my application from other pc connected in same network, cookie is not deleted and application is not logged out.
Upvotes: 0
Views: 291
Reputation: 2049
Users can still browse your website because cookies are not cleared when you call FormsAuthentication.SignOut()
and they are authenticated on every new request. In MS documentation is says that cookie will be cleared but they don't, bug? Its exactly the same with 'Session.Abandon()',
cookie is still there.
You should change your code to this:
FormsAuthentication.SignOut();
Session.Abandon();
// clear authentication cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
// clear session cookie (not necessary for your current problem but i would recommend you do it anyway)
HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
cookie2.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie2);
FormsAuthentication.RedirectToLoginPage();
Upvotes: 0