我試圖實現「編寫信息到用戶數據」部分this article,但它在Cookie是URI的一部分時無法正常工作。無法在無Cookie模式下設置FormsAuthenicationTicket.UserData
我的代碼:
// Create the cookie that contains the forms authentication ticket
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(userName, createPersistantCookie);
// Get the FormsAuthenticationTicket out of the encrypted cookie
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
// Create a new FormsAuthenticationTicket that includes our custom User Data
FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, "foo");
// Update the authCookie's Value to use the encrypted version of newTicket
authCookie.Value = FormsAuthentication.Encrypt(newTicket);
// Manually add the authCookie to the Cookies collection
HttpContext.Current.Response.Cookies.Add(authCookie);
// Determine redirect URL and send user there
string redirUrl = FormsAuthentication.GetRedirectUrl(userName, createPersistantCookie);
HttpContext.Current.Response.Redirect(redirUrl, false);
當cookie的使用,頁面重定向,但在它的cookie信息沒有得到正確的URI,所以它返回到哪裏Request.IsAuthenticated回報我的登錄頁面假。無盡的循環隨之而來。
如何重定向到正確的URI?
聽起來像是不錯的計劃:) – 2008-11-05 20:10:41