我在 sharePoint 2013 中为 FBA 使用 Asp.net memebership 提供程序。请告诉我如何动态查找会员提供程序名称。
提前致谢。
我在 sharePoint 2013 中为 FBA 使用 Asp.net memebership 提供程序。请告诉我如何动态查找会员提供程序名称。
提前致谢。
感谢您的回复。我的场景是我动态地计划获取会员提供者,因为我必须在表单身份验证期间创建令牌。我找到了答案
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;
}
希望这段代码对某人有所帮助。
谢谢拉玛
这很容易,在 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());
}