【问题标题】:Forms authentication for www and without wwwwww 和不带 www 的表单身份验证
【发布时间】:2013-03-23 15:13:22
【问题描述】:

这是我的配置文件的一部分

<authentication mode="Forms">
   <forms loginUrl="~/Account/Login" timeout="2880" enableCrossAppRedirects="true"
          name="authtoken" domain="localsite.com" />
</authentication>

这是我的身份验证方法

public void Authenticate(string token, int userId)
{
    var userData = new FormTicketUserData() {UserId = userId};
    var ticket = new FormsAuthenticationTicket(1, token, DateTime.Now, DateTime.MaxValue,  
                                               false, userData.ToString());
    var encryptString = FormsAuthentication.Encrypt(ticket);
    var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptString);
    authCookie.Path = FormsAuthentication.FormsCookiePath;
    HttpContext.Current.Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
    HttpContext.Current.Response.Cookies.Add(authCookie);
    HttpContext.Current.User = new MyFormsPrincipal(new FormsIdentity(ticket), userId);
    UserContext.Refresh();
}

当我在 www.localsite.com 上进行身份验证时,我不在 localsite.com 上进行身份验证,反之亦然。
当我在 www.localsite.com 上进行身份验证时,我也需要在 localsite.com 上进行身份验证。
我怎样才能做到这一点。

【问题讨论】:

  • 我可以建议一个规范的域名吗?

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


【解决方案1】:

这个问题解决了

authCookie.Domain = "localsite.com";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 2011-05-15
    • 2017-03-19
    • 1970-01-01
    • 2015-01-10
    • 1970-01-01
    相关资源
    最近更新 更多