1

我正在使用 .net 3.5 的现有项目的 .net 4.5 中创建一个新项目。它的工作方式是他们通过登陆站点登录,然后在那里他们选择要访问的两个站点中的哪一个。所有站点都有一个机器密钥集。

我将网站设置为这种方式

  • a.site.com - 登陆页面
  • b.site.com
  • c.site.com

.net 3.5 版本的应用程序工作,但我无法让应用程序的 4.5 版本工作。它让我登录到登录页面,但每次我访问站点 b 或 c 时,它都会将我重定向回登录页面。我已经检查了所有三个应用程序的 web config 中的配置,它们使用相同的机器密钥和表单信息。这是我正在使用的格式配置。

        <machineKey validationKey="ZZZ" decryptionKey="YYY" validation="SHA1" decryption="AES" />

    <authentication mode="Forms">
        <forms name=".FormName" loginUrl="http://a.site.com/login.htm" defaultUrl="default.aspx" protection="All" timeout="15" path="/" requireSSL="false" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseDeviceProfile" domain="site.com" />
    </authentication>

我已阅读此站点上的机器密钥存在问题,但这些问题似乎适用于运行不同 .net 版本的不同应用程序。我正在使用的新应用程序运行相同的 .net 版本并托管在 Microsoft Server 2008 上。我不确定我缺少什么配置/设置会导致这种情况。有谁知道我可能做错了什么?

更新 :

这是我使用的代码:

将 MyGuid 调暗为 Guid = Guid.NewGuid()

            Dim sSSO_ID As String = Guests.AddSSOIDForDirectLogin(iGuestID, MyGuid.ToString)

            ' first write the authentication cookie to 
            ' the machine so we know the user is sSSO_ID
            'FormsAuthentication.SetAuthCookie(sSSO_ID, False)

            Dim sPersistentCookie As Boolean = False

            Dim t As New FormsAuthenticationTicket(1, sSSO_ID, DateTime.Now, DateTime.Now.AddMonths(3), sPersistentCookie, sSSO_ID.ToString, FormsAuthentication.FormsCookiePath)
            Dim eTicket As String = FormsAuthentication.Encrypt(t)
            Dim c As New HttpCookie(FormsAuthentication.FormsCookieName, eTicket)

            If sPersistentCookie = True Then
                c.Expires = DateTime.Now.AddMonths(3)
            End If


            Response.Cookies.Add(c)

原来我注释掉了设置域的 SetAuthCookie。我创建的表单身份验证票证没有设置域。SetAuthCookie 是不是类似于创建表单身份验证票,所以两者都是必要的?只需在添加 cookie 之前添加 c.Domain="site.com"

4

0 回答 0