1

SharePoint 2013 で FBA に Asp.net メンバーシップ プロバイダーを使用しています。メンバーシップ プロバイダー名を動的に検索する方法を教えてください。

前もって感謝します。

4

2 に答える 2

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;
}

このコードが誰かに役立つことを願っています。

ありがとうラーマ

于 2014-12-14T09:56:11.233 に答える
0

これは非常に簡単です。CSOM で現在のユーザー名を取得します (フォーム ベースのアカウントでログインしている場合)。ユーザー名は次の形式になります。

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

「i:0#.f|メンバーシップ|someone.example.com」は、メンバーシップ プロバイダー名です。このセクションを取得するには、javascript サブストリング関数を使用します。

現在のユーザーのログイン名を取得するには、ここでも提供されている次のコードを使用します

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());
}

于 2014-12-11T13:48:04.953 に答える