Get membership provider Name

1.8k views Asked by At

I am using Asp.net memebership provider for FBA in sharePoint 2013. Please let me know how to dynamically find membership provider name.

Thanks in advance.

2

There are 2 answers

0
user812824 On BEST ANSWER

Thanks for the response. My scenario is I am dynamically planning to get membership provider as I have to create token during forms authentication. I found the answer

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

Hope this code helps someone.

Thanks Rama

0
Godwin On

This is quite easy , in CSOM get the current username (if you are logged in with a forms based account) .The username will be of the following format :

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

The "i:0#.f|membership|someone.example.com" is the membership provider name. Use javascript substring function to get this section.

To get the current user loginname, use the following code which is also provided here

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