2014-09-10 131 views
1

我正尝试在新环境中设置我的网站,并且我遇到了成员资格提供方的问题。SetAuthCookie未在我们的测试服务器上设置Cookie

我可以调用Membership.ValidateUser,它会返回true和false,因为它应该如此。这是完美的。

但是,在我的新环境中,cookie从未设置。我可以在本地主机和我们的生产服务器上看到它设置了一个名为CommunityServer的cookie,但不在我们的新环境中。

的Web.config代码

<authentication mode="Forms"> 
     <!-- development --> 
     <forms name=".CommunityServer" protection="All" timeout="60000" loginUrl="~/user/login" slidingExpiration="true"/> 
     <!-- deployment --> 
     <!--<forms name=".CommunityServer" domain="domain.com" protection="All" timeout="60000" loginUrl="~/user1.aspx" slidingExpiration="true" />--> 
    </authentication> 
    <authorization> 
     <allow users="?"/> 
    </authorization> 

代码登录:

if (String.IsNullOrEmpty(UsernameLogin)) { 
       ModelState.AddModelError("UsernameLogin", Strings.Error_NoLoginUsernameEntered); 
      } 
      if (String.IsNullOrEmpty(PasswordLogin)) { 
       ModelState.AddModelError("PasswordLogin", Strings.Error_NoLoginPasswordEntered); 
      } 
      if (!Membership.ValidateUser(UsernameLogin, PasswordLogin)) { 
       ModelState.AddModelError("UsernameLogin", Strings.Error_LoginFailed); 
      } 


      if (!ModelState.IsValid) { 
       return View(new UserLoginModel() { Title = String.Format(Strings.Site_Title, Strings.UserLogin_Title) }); 
      } 

      FormsAuthentication.SetAuthCookie(UsernameLogin, true); 

      // we know this code is run and I am being redirected to the return url 
      if (!String.IsNullOrEmpty(ReturnUrl)) { 
       return Redirect(ReturnUrl); 
      } 

有关提示的任何想法,为什么我们的Cookie从未设置?它是一个IIS 8服务器。

+1

试着设置正确的'domain'参数,就像你在注释中所做的那样。 – Aristos 2014-09-10 11:33:50

回答

1

将身份验证的参数添加domain="domain.com",要求cookie对整个域有效,并对正确的域有效,否则有可能无法设置。

<authentication mode="Forms"> 
     <!-- development --> 
     <forms name=".CommunityServer" domain="domain.com" protection="All" timeout="60000" loginUrl="~/user/login" slidingExpiration="true"/>