SetAuthCookie不设置cookie的我们的测试服务器上 [英] SetAuthCookie does not set cookie on our test server

查看:252
本文介绍了SetAuthCookie不设置cookie的我们的测试服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置我的网站上一个新的环境,我与成员提供的一个问题。

I am trying to setup my website on a new environment, and I have a problem with the membership provider.

我可以叫 Membership.ValidateUser ,返回真与假,因为它应该。这是完美的。

I can call Membership.ValidateUser, which returns true and false, as it should. That is perfect.

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

However, on my new environment, the cookie is never set. I can see on localhost and our production server, that it sets a cookie called CommunityServer, but not on our new environment.

的Web.config code

<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>

登录code

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服务器。

Any ideas of hints about why our cookie is never set? It is an IIS 8 server.

推荐答案

添加域=domain.com身份验证的parametre,要说到cookie为有效,以完整的域,并以正确的域,否则有不能够被设置的可能性。

Add the domain="domain.com" on the parametre of authentication, to say to the cookie to be valid to the full domain, and to the correct domain, or else there is the possibility to not been able to be set.

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

这篇关于SetAuthCookie不设置cookie的我们的测试服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆