【发布时间】:2014-11-04 00:48:54
【问题描述】:
我正在尝试在新环境中设置我的网站,但我遇到了会员提供商的问题。
我可以调用Membership.ValidateUser,它应该返回真假。这是完美的。
但是,在我的新环境中,从未设置过 cookie。我可以在 localhost 和我们的生产服务器上看到它设置了一个名为 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参数,就像您在 cmets 上设置的那样。
标签: c# asp.net cookies asp.net-membership iis-8