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服務器。
試着設置正確的'domain'參數,就像你在註釋中所做的那樣。 – Aristos 2014-09-10 11:33:50