简体   繁体   English

在SharePoint 2010中使用我的旧成员资格提供程序

[英]Using my old membership provider in SharePoint 2010

I've got a custom membership provider that I use both in SharePoint 2007 services and in .NET web apps. 我有一个自定义成员资格提供程序,可在SharePoint 2007服务和.NET Web应用程序中使用。 Now I'm trying to update the SharePoint platform to 2010 Foundation and my provider doesn't work. 现在,我正在尝试将SharePoint平台更新为2010 Foundation,而我的提供程序不起作用。 Below is two examples that both authenticate a user and sets a auth cookie with the same key. 以下是两个对用户进行身份验证并使用相同密钥设置身份验证cookie的示例。

MembershipProvider provider = Membership.Providers["Provider"];

//Alternative one using cookiename (ProviderUserKey from other source then provider)
if (provider.ValidateUser(user, passwd))
{
    FormsAuthentication.SetAuthCookie(cookieName, false);
    Response.Redirect("/");
}
else
{
    ShowErrorMsg();
}

//Alternative two using provider to get ProviderUserKey same as cookieName above
if (provider.ValidateUser(user, passwd))
{
    MembershipUser memberUser = provider.GetUser(user, false); //false or true doesnt matter in this provider
    FormsAuthentication.SetAuthCookie(memberUser.ProviderUserKey.ToString(), false);
    Response.Redirect("/");
}
else
{
    ShowErrorMsg();
}

The problem is that SharePoint 2010 uses Claims-based identity and i did try the following but with no success. 问题在于SharePoint 2010使用基于声明的身份,我确实尝试了以下操作,但没有成功。

MembershipProvider provider = Membership.Providers["Provider"];

if (provider.ValidateUser(user, passwd))
{
    SPFormsAuthenticationProvider authProvider = IisSetting.FormsClaimsAuthenticationProvider;

    SecurityToken token = SPFormsUserNameSecurityTokenHandler.CreateSecurityToken(authProvider.MembershipProvider, cookieName, passwd);
    SPFederationAuthenticationModule.Current.SetPrincipalAndWriteSessionToken(token);
}

But this doesn't work for me. 但这对我不起作用。 Does anyone know how to base a claims identity on another key then the provided username. 有谁知道如何将声明身份基于另一个密钥,然后提供的用户名。

If you are use Claim-based authentication with FBA than you should use like : 如果您将Claim-based authenticationFBA使用,则应使用以下方式:

  bool status = SPClaimsUtility.AuthenticateFormsUser(Context.Request.UrlReferrer, UserName, Password);
  if (status)
  {
          // do your stuff.
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM