寻找活跃的会员提供者并确保其在 Sharepoint 2010 中的可用性
Finding active Membership Provider and ensure its availability in Sharepoint 2010
如何找出当前活跃的会员提供者并查看它是否可用?
我用下面的函数来解决这个问题。
此函数查找当前的成员资格提供者和角色提供者,并使用其功能之一 (ValidateUser) 查明成员资格提供者是否可用以及 运行.
private bool CheckMembershipProvider()
{
try
{
string username = txtboxUserName.Text;
string password = txtboxPassword.Text;
if (!SPContext.Current.Web.UserIsSiteAdmin)
{
txtCurrentMembershipProviderError.Text = "You need to be admin.";
return false;
}
var spIisSettings = SPContext.Current.Site.WebApplication.GetIisSettingsWithFallback(SPContext.Current.Site.Zone);
var membershipProviderName = spIisSettings.FormsClaimsAuthenticationProvider != null ? spIisSettings.FormsClaimsAuthenticationProvider.MembershipProvider : null; ;
var roleProviderName = spIisSettings.FormsClaimsAuthenticationProvider != null ? spIisSettings.FormsClaimsAuthenticationProvider.RoleProvider : null;
txtMembershipProviderName.Text = membershipProviderName != null? membershipProviderName.ToString(): "----";
txtRoleProviderName.Text = roleProviderName.ToString();
var provider = spIisSettings.FormsClaimsAuthenticationProvider != null ? Membership.Providers[spIisSettings.FormsClaimsAuthenticationProvider.MembershipProvider] : null;
if (provider != null)
{
var method = provider.GetType().GetMethod("ValidateUser", new Type[] { typeof(string), typeof(string) });
if (method != null)
{
try
{
bool valid = (bool)method.Invoke(provider, new object[] {username, password });
txtCurrentMembershipProviderError.Text = valid ? "Valid user":"Invalid user";
return true;
}
catch (Exception ex)
{
txtCurrentMembershipProviderError.Text = "Provider is not accessible. " + ex.Message ;
return false;
}
}
else
{
txtCurrentMembershipProviderError.Text = "No prepare admin login method in default membership provider (" + provider.GetType().Name + ")";
return false;
}
}
else
{
txtCurrentMembershipProviderError.Text = "No default membership provider";
return false;
}
}
catch (Exception ex)
{
txtCurrentMembershipProviderError.Text = ex.Message;
return false;
}
}
如何找出当前活跃的会员提供者并查看它是否可用?
我用下面的函数来解决这个问题。 此函数查找当前的成员资格提供者和角色提供者,并使用其功能之一 (ValidateUser) 查明成员资格提供者是否可用以及 运行.
private bool CheckMembershipProvider()
{
try
{
string username = txtboxUserName.Text;
string password = txtboxPassword.Text;
if (!SPContext.Current.Web.UserIsSiteAdmin)
{
txtCurrentMembershipProviderError.Text = "You need to be admin.";
return false;
}
var spIisSettings = SPContext.Current.Site.WebApplication.GetIisSettingsWithFallback(SPContext.Current.Site.Zone);
var membershipProviderName = spIisSettings.FormsClaimsAuthenticationProvider != null ? spIisSettings.FormsClaimsAuthenticationProvider.MembershipProvider : null; ;
var roleProviderName = spIisSettings.FormsClaimsAuthenticationProvider != null ? spIisSettings.FormsClaimsAuthenticationProvider.RoleProvider : null;
txtMembershipProviderName.Text = membershipProviderName != null? membershipProviderName.ToString(): "----";
txtRoleProviderName.Text = roleProviderName.ToString();
var provider = spIisSettings.FormsClaimsAuthenticationProvider != null ? Membership.Providers[spIisSettings.FormsClaimsAuthenticationProvider.MembershipProvider] : null;
if (provider != null)
{
var method = provider.GetType().GetMethod("ValidateUser", new Type[] { typeof(string), typeof(string) });
if (method != null)
{
try
{
bool valid = (bool)method.Invoke(provider, new object[] {username, password });
txtCurrentMembershipProviderError.Text = valid ? "Valid user":"Invalid user";
return true;
}
catch (Exception ex)
{
txtCurrentMembershipProviderError.Text = "Provider is not accessible. " + ex.Message ;
return false;
}
}
else
{
txtCurrentMembershipProviderError.Text = "No prepare admin login method in default membership provider (" + provider.GetType().Name + ")";
return false;
}
}
else
{
txtCurrentMembershipProviderError.Text = "No default membership provider";
return false;
}
}
catch (Exception ex)
{
txtCurrentMembershipProviderError.Text = ex.Message;
return false;
}
}