MVC3 FormsAuthenticationTicket Cookie名称

时间:2012-08-27 08:58:29

标签: asp.net-mvc-3 authentication forms-authentication

  

可能重复:   Can I change the FormsAuthentication cookie name?

我有多个创建FormsAuthentication票证的MVC3站点并将它们存储在cookie中。

登录:

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(15), true, String.Empty);
string encTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);

在Application_AuthenticateRequest中:

HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; 

如果多个网站保存到同一个Cookie,这肯定会导致问题? 为每个应用程序设置不同的cookie名称是否有任何损害,或者是否有另一种推荐方法可以做到这一点?

1 个答案:

答案 0 :(得分:2)

如果这些多个网站位于同一个网域,则只会导致问题。

您可以在web.config中设置Cookie名称 - 请参阅Can I change the FormsAuthentication cookie name?

相关问题