2

我有一个在 Sharepoint 上运行的公共网站。现在,当用户登录时,我们希望他们能够选择“记住登录”,这样他们就有了持久登录。

据我了解,Sharepoint 支持这一点。您唯一需要做的就是运行:

spFederationAuthenticationModule.SetPrincipalAndWriteSessionToken(someSessionSecurityToken, true);

现在,我不知道如何获得重载所需的 SessionSecurityToken。目前我们使用的是没有 true 的。

我们的代码:

MembershipProvider membershipProvider = Membership.Providers["CustomProvider"];

            VerifyCredentialsResult verifyCredentialsDto = null;

            using (WindowsIdentity.Impersonate(IntPtr.Zero))
            {
                var customerService = Kernel.Resolve<ICustomerServiceAgent>();
                verifyCredentialsDto = customerService.VerifyCredentials(userName, passwordOrSsoToken);
                Kernel.ReleaseComponent(customerService);
            }

            if (!verifyCredentialsDto.Succes)
                return false;

            SecurityToken securityToken =
                SPSecurityContext.SecurityTokenForFormsAuthentication(new Uri(SPContext.Current.Web.Url),
                                                                      "CustomProvider",
                                                                      "CustomRoleProvider",
                                                                      verifyCredentialsDto.CustomerId,
                                                                      passwordOrSsoToken);
            if (securityToken != null)
            {
                SPFederationAuthenticationModule spFederationAuthenticationModule =
                    SPFederationAuthenticationModule.Current;

                spFederationAuthenticationModule.SetPrincipalAndWriteSessionToken(securityToken);
                return true;
            }
            return false;

实现持久性真/假参数很容易,但是我们如何更改代码以在登录时支持持久性cookie?

4

0 回答 0