获取会员提供者姓名

时间:2014-12-11 11:04:11

标签: sharepoint sharepoint-2013 fba

我在sharePoint 2013中使用Asp.net会员提供商进行FBA。请告诉我如何动态查找会员提供商名称。

提前致谢。

2 个答案:

答案 0 :(得分:2)

感谢您的回复。 我的情况是我正在动态计划获得成员资格提供者,因为我必须在表单身份验证期间创建令牌。 我找到了答案

private static string GetFbaZoneUrl(SPWeb web)
{
    string providerAndRole = null;
    SPWebApplication webApp = web.Site.WebApplication;
    foreach (var zone in webApp.IisSettings.Keys)
    {
        var settings = webApp.IisSettings[zone];
        var fbaProvider = webApp.IisSettings[zone].FormsClaimsAuthenticationProvider;

        if (fbaProvider != null)
        {
            // We found the zone on the web app where FBA is enabled.
            // This is the zone whose URL we want.
            // SPAlternateUrl fbaUrl = webApp.AlternateUrls.GetResponseUrl(zone, false);
            providerAndRole = fbaProvider.MembershipProvider + "," + fbaProvider.RoleProvider;
            break;
        }
    }

    return providerAndRole;
}

希望此代码可以帮助某人。

由于 拉马

答案 1 :(得分:0)

这很简单,在CSOM中获取当前用户名(如果您使用基于表单的帐户登录)。用户名将采用以下格式:

"i:0#.f|membership|someone.example.com"

“i:0#.f | 会员 | someone.example.com”是会员提供商名称。使用javascript substring函数获取此部分。

要获取当前用户的登录名,请使用以下代码({3}}

function GetCurrentUsername()
{
var ctxt = new SP.ClientContext.get_current();
this.website = ctxt.get_web();
this.currentUser = website.get_currentUser();
ctxt.load(currentUser);
ctxt.executeQueryAsync(Function.createDelegate(this, this.onSucceess), Function.createDelegate(this, this.onFail));
}



function onSucceess(sender, args)
 {
 alert(currentUser.get_loginName());
 }



function onFail(sender, args)
{
alert('request failed ' + args.get_message() + '\n'+ args.get_stackTrace());
}