ASP.NET Authentication Cookies - Change Users

I create authentication cookies using the following code:

string formsCookieStr = string.Empty;
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
            1,                              // version
            username,                       // user name
            DateTime.Now,                   // issue time
            DateTime.Now.AddMinutes(30),    // expires
            false,                          // Persistence
            userRoleData                    // user data
    );
formsCookieStr = FormsAuthentication.Encrypt(ticket);
HttpCookie FormsCookie = new HttpCookie(FormsAuthentication.FormsCookieName, formsCookieStr);
HttpContext.Response.Cookies.Add(FormsCookie);

If the second user tries to log in from the same client computer before the first user logs out, will the above code contain two cookies existing on the client? If so, how can I prevent this from happening? Thanks

+3
source share
2 answers

FormsAuthentication.FormsCookieName sets a cookie name, so there is only one cookie to check if you name it FormsAuthentication.FormsCookieName

+2
source

, cookie: Response.Cookies.Clear();, .

, 2 ( 2 ) , Cookie .

-1

All Articles