Sharepoint 2013 FBA错误:无法检索IIS Settings.Parameter名称:context

时间:2014-10-14 03:23:02

标签: sharepoint-2013 fba

(原帖在这里:https://social.technet.microsoft.com/Forums/sharepoint/en-US/6b02dfe8-5594-4d25-991a-51ac9a0528b7/sharepoint-2013-fba-errorcould-not-retrieve-the-iis-settingsparameter-name-context?forum=sharepointadminprevious

我正在尝试使用windows live登录sharepoint 2013.从某些帖子中,我可以获得windows live token(aouth 2.0)和windows live用户个人资料。它将重定向到我的sharepoint网站。

我按照一些文章来开发我的自定义登录页面:

我也定义了我的会员提供者和角色提供者

public class LiveMembershipProvider : MembershipProvider
{
    private MembershipUserCollection employees;
    private void generateUsers()
    {
   //Mock Data
        employees = new MembershipUserCollection();
        employees.Add(new MembershipUser(this.Name, "Jack Chen", "JackChen", "Jack@Chen.com", "What your Name?", "I am Jack", true, false, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today));
        employees.Add(new MembershipUser(this.Name, "Bruce Li", "BruceLi", "BruceLi@Li.com", "How are u?", "How old are u", true, false, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today));
        employees.Add(new MembershipUser(this.Name, "Eyes Wang", "EyesWang", "EyesWang@Mintcode.com", "What the hell?", "what the fuck", true, false, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today));
    }
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
    if (employees == null) generateUsers();
    MembershipUserCollection returnFoundUsers = new MembershipUserCollection();

    (employees.Cast<MembershipUser>().
        Where(membershipUser => membershipUser.UserName.ToLowerInvariant().Contains(usernameToMatch.ToLowerInvariant())))
        .ToList().ForEach(returnFoundUsers.Add);

    totalRecords = returnFoundUsers.Count;
    return returnFoundUsers;
}

public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
    if (employees == null) generateUsers();
    totalRecords = employees.Count;
    return employees;
}

public override MembershipUser GetUser(string username, bool userIsOnline)
{
    if (employees == null) generateUsers();
    IEnumerable<MembershipUser> usersFound = employees.Cast<MembershipUser>().Where(membershipUser => membershipUser.UserName == username);
    return usersFound.FirstOrDefault();
}

public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
    if (employees == null) generateUsers();
    IEnumerable<MembershipUser> usersFound = employees.Cast<MembershipUser>().Where(membershipUser => membershipUser.ProviderUserKey.ToString() == providerUserKey.ToString());
    return usersFound.FirstOrDefault();
}

public override string GetUserNameByEmail(string email)
{
    if (employees == null) generateUsers();
    IEnumerable<MembershipUser> usersFound = employees.Cast<MembershipUser>().Where(membershipUser => membershipUser.Email.ToLowerInvariant() == email.ToLowerInvariant());
    MembershipUser user = usersFound.FirstOrDefault();

    if (user != null)
        return user.UserName;
    else
        return null;
}

public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
{

    if (employees == null) generateUsers();
    MembershipUserCollection returnFoundUsers = new MembershipUserCollection();

    (employees.Cast<MembershipUser>().
     Where(membershipUser => membershipUser.Email.ToLowerInvariant().Contains(emailToMatch.ToLowerInvariant())))
        .ToList().ForEach(returnFoundUsers.Add);

    totalRecords = returnFoundUsers.Count;

    return returnFoundUsers;

}

public override bool ValidateUser(string username, string password)
{
    //return true;
    if (employees == null) generateUsers();

    IEnumerable<MembershipUser> usersFound = employees.Cast<MembershipUser>().Where(membershipUser => membershipUser.UserName == username);
    MembershipUser user = usersFound.FirstOrDefault();

    if (user != null)
    {
        if (string.IsNullOrEmpty(password))
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    else
        return false;
}

}

public class LiveRoleProvider:RoleProvider {     public override string ApplicationName {get;组; }

private string[] m_AllRoles = { "Vendor" };

private string[,] m_RolesForUser = new string[,] {
    {"Eyes Wang", "Vendor"},
    {"Bruce Li","Vendor"},
    {"Jack Chen","Vendor"}
};

public override string[] GetAllRoles()
{

    return m_AllRoles;

}

public override string[] GetRolesForUser(string username)

{
    List<string> roles = new List<string>();
    for (int i = 0; i <= m_RolesForUser.GetUpperBound(0); i++)
    {

        if (m_RolesForUser[i, 0] == username)
        {
            roles = m_RolesForUser[i, 1].Split(',').ToList<string>();
        }

    }
    return roles.ToArray();
}

  public override string[] GetUsersInRole(string rolename)
  {

      List<string> users = new List<string>();
      for (int i = 0; i <= m_RolesForUser.GetUpperBound(0); i++)
       {
           List<string> userRoles = m_RolesForUser[i, 1].Split(',').ToList<string>();
           if (userRoles.Where(userRole => userRole == rolename).Count() > 0)
          {

             users.Add(m_RolesForUser[i, 0]);
          }

      }
      return users.ToArray();
   }


 public override bool IsUserInRole(string username, string rolename)
 {

      List<string> usersForRole = GetUsersInRole(rolename).ToList();
      if (usersForRole.Where(userName => userName == username).Count() > 0)
      {
          return true;
      }

      else
      {
          return false;
      }

 }

public override bool RoleExists(string rolename)
{

     bool roleExsists = m_AllRoles.ToList().Where(roleName => roleName == rolename).Count() > 0;
     return roleExsists;
}

public override string[] FindUsersInRole(string rolename, string usernameToMatch)
{

    List<string> users = GetUsersInRole(rolename).ToList<string>();
    List<string> foundUsers = users.Where(userName => userName.ToLowerInvariant().Contains(usernameToMatch.ToLowerInvariant())).ToList<string>();
    return foundUsers.ToArray();

}     }

在Central Application web.config中

我添加

<roleManager>
      <providers>
        <add name="LiveRoleProvider" type="SPLiveWebForm.LiveRoleProvider,SPLiveWebForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=34a64026791bbfa4" />
      </providers>
    </roleManager>
    <membership>
      <providers>
        <add name="LiveMembershipProvider" type="SPLiveWebForm.LiveMembershipProvider,SPLiveWebForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=34a64026791bbfa4" />      
      </providers>
    </membership>
    <PeoplePickerWildcards>
      <clear />
      <add key="AspNetSqlMembershipProvider" value="%" />
      <add key="LiveMembershipProvider" value="%" />
    </PeoplePickerWildcards>

在WA web.config

<membership defaultProvider="i">
  <providers>
    <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
    <add name="LiveMembershipProvider" type="SPLiveWebForm.LiveMembershipProvider,SPLiveWebForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=34a64026791bbfa4" />
  </providers>
</membership>
<roleManager defaultProvider="c" enabled="true" cacheRolesInCookie="false">
  <providers>
    <add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
    <add name="LiveRoleProvider" type="SPLiveWebForm.LiveRoleProvider,SPLiveWebForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=34a64026791bbfa4" />
  </providers>
</roleManager>
<PeoplePickerWildcards>
  <clear />   
  <add key="AspNetSqlMembershipProvider" value="%" />
  <add key="LiveMembershipProvider" value="%" />
</PeoplePickerWildcards>

在STS web.config

   <system.web>
         <membership defaultProvider="i">
          <providers>
            <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
            <add name="LiveMembershipProvider" type="SPLiveWebForm.LiveMembershipProvider,SPLiveWebForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=34a64026791bbfa4" />
          </providers>
        </membership>
        <roleManager defaultProvider="c" enabled="true" cacheRolesInCookie="false">
          <providers>
            <add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
            <add name="LiveRoleProvider" type="SPLiveWebForm.LiveRoleProvider,SPLiveWebForm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=34a64026791bbfa4" />
          </providers>
        </roleManager>
      </system.web>

我可以使用默认登录页面(http://www.akmii.com/_forms/default.aspx

成功登录共享点

但是使用我的自定义页面(当我获得windows live用户配置文件然后尝试使用follow方法登录sharepoint时)

private void SPUserLogin(string usrName)
    {
        string userProviderName = string.Empty;
        string roleProviderName = string.Empty;
        foreach (MembershipProvider p in Membership.Providers)
        {
            if (p.GetType().Equals(typeof(LiveMembershipProvider)))
            {
                userProviderName = p.Name;
                break;
            }
        }

        foreach (RoleProvider rp in System.Web.Security.Roles.Providers)
        {
            if (rp.GetType().Equals(typeof(LiveRoleProvider)))
            {
                roleProviderName = rp.Name;
                break;
            }
        }

        SecurityToken tk = null;
        try
        {
            tk = SPSecurityContext.SecurityTokenForFormsAuthentication(
               new Uri(SPContext.Current.Web.Url), userProviderName, roleProviderName,
             "Jack Chen", "123", SPFormsAuthenticationOption.PersistentSignInRequest);
        }
        catch (Exception e)
        {
            Response.Write(e.Message);
        }
        if (tk != null)
        {
            //try setting the authentication cookie
            SPFederationAuthenticationModule fam = SPFederationAuthenticationModule.Current;
            fam.SetPrincipalAndWriteSessionToken(tk);

            //look for the Source query string parameter and use that as the redirection
            //string src = Request.QueryString["Source"];
            string src = "http://www.akmii.com/_layouts/15/start.aspx#/SitePages/Home.aspx";
            if (!string.IsNullOrEmpty(src))
                Response.Redirect(src);
        }
        else
        {

        }


    }
}

在捕获部分抛出异常:

无法检索IIS Settings.Parameter名称:context

错误堆栈如下:

   at Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannel.ReadResponse(Message response)
   at Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannel.Issue(RequestSecurityToken rst, RequestSecurityTokenResponse& rstr)
   at Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannel.Issue(RequestSecurityToken rst)
   at Microsoft.SharePoint.SPSecurityContext.SecurityTokenForContext(Uri context, Boolean bearerToken, SecurityToken onBehalfOf, SecurityToken actAs, SecurityToken delegateTo, SPRequestSecurityTokenProperties properties)
   at Microsoft.SharePoint.SPSecurityContext.SecurityTokenForFormsAuthentication(Uri context, String membershipProviderName, String roleProviderName, String username, String password, SPFormsAuthenticationOption options)
   at SPLiveWebForm.Layouts.SPLiveWebForm.Login.SPUserLogin(String usrName)

如果我使用

bool status = SPClaimsUtility.AuthenticateFormsUser(
                     new Uri(SPContext.Current.Web.Url),
                     usrName,
                     "123");

抛出同样的例外。

   at Microsoft.SharePoint.IdentityModel.SPFormsOriginalIssuerBuilder.GetFormsAuthenticationProviderFromContext(Uri context)
   at Microsoft.SharePoint.IdentityModel.SPFormsOriginalIssuerBuilder.ValidateFormsAuthProviderNames(Uri context, String membershipProvider, String roleProvider)
   at Microsoft.SharePoint.IdentityModel.SPFormsOriginalIssuerBuilder.SetProviderNames()
   at Microsoft.SharePoint.IdentityModel.SPSecurityTokenService.SPRequestInfo.InitializeForForms(SPRequestSecurityToken request)
   at Microsoft.SharePoint.IdentityModel.SPSecurityTokenService.GetTokenLifetime(Lifetime requestLifetime)
   at Microsoft.IdentityModel.SecurityTokenService.SecurityTokenService.Issue(IClaimsPrincipal principal, RequestSecurityToken request)
   at Microsoft.SharePoint.IdentityModel.SPSecurityTokenService.Issue(IClaimsPrincipal principal, RequestSecurityToken request)
   at Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract.DispatchRequest(DispatchContext dispatchContext)
   at Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract.ProcessCore(Message requestMessage, WSTrustRequestSerializer requestSerializer, WSTrustResponseSerializer responseSerializer, String requestAction, String responseAction, String trustNamespace)
   at Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract.ProcessTrust13Issue(Message message)
   at SyncInvokeProcessTrust13Issue(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

我花了一整天时间来挖掘这个问题但却失败了。

有解决方法吗?

非常感谢!

文森特

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。 在我的情况下,我不得不去Central Administartion =&gt;系统设置=&gt;配置备用访问映射。

单击“编辑公共URL”,在“备用访问映射集”中选择您的应用程序,然后填写“Internet”文本框。 我不确定什么值是正确的,但我使用默认(80)端口填充了我的sharepoint URL。

希望对你有所帮助。