0
我想通過使用下面的代碼創建窗體身份驗證Cookie。雖然這對於持久登錄非常有效,但當我關閉瀏覽器會話時,非持久性Cookie不會過期並從瀏覽器中刪除。它仍然保留在瀏覽器中。FormsAuthentication非持久性Cookie不會在MVC 4中過期應用程序
public static void SetAuthenticationCookie(string userName, Role role,
bool isPersistent)
{
string data = role.RoleName;
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(userName,isPersistent);
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
FormsAuthenticationTicket newticket = new FormsAuthenticationTicket(
ticket.Version, ticket.Name, ticket.IssueDate,ticket.Expiration,
ticket.IsPersistent,data);
authCookie.Value = FormsAuthentication.Encrypt(newticket);
HttpContext.Current.Response.Cookies.Add(authCookie);
}
這裏是窗體身份驗證
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" cookieless="UseCookies" name=".OneClick"
protection="All" slidingExpiration="true" timeout="43200" />
</authentication>
這裏的web.config條目的cookie信息從瀏覽器
截圖有什麼我失蹤這裏?請讓我知道