public static Boolean AdminUser(string userId, string userPwd)
{
Boolean isPassAdmin = false;
MembershipProvider domainProvider;
MembershipUser user = Membership.GetUser(userId);
foreach (ProviderBase provider in Membership.Providers)
{
domainProvider = Membership.Providers[provider.Name];
try
{
if (domainProvider.ValidateUser(userId, userPwd))
{
isPassAdmin = true;
}
}
catch (Exception e)
{
throw e;
}
}
return isPassAdmin;
}
webconfig
<connectionStrings>
<add name="emiteCubeConnectionString" connectionString="Data Source=CfxixiDB; Catalog=cfxixi357" providerName="Dundas.Olap.Data.AdomdNet.AdomdNetDataProvider" />
<add name="Emitebusiness.Properties.emiteDbConnectionString" connectionString="Data Source=cfxixiDB;Initial Catalog=cfxixi357;Integrated Security=True;Connect Timeout=300;" providerName="System.Data.SqlClient" />
<add name="Emitebusiness.Properties.aspnetdbConnectionString" connectionString="Data Source=cfxixiDB;Initial Catalog=cfxixi357;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="ADMembershipProvider" connectionString="LDAP://CfxixiAD.emite.local/DC=cfxixi,DC=local" />
<add name="ADGroupSearchRoot" connectionString="LDAP://CfxixiAD.emite.local/OU=sa,DC=cfxixi,DC=local" />
<add name="GlobalCatalogConnectionString" connectionString="GC://dc=cfxixi,dc=local" />
</connectionStrings>
<system.web>
<membership defaultProvider="ADMembershipProvider">
<providers>
<remove name="AspNetSqlMembershipProvider" />
<remove name="ADMembershipProvider" />
<add connectionStringName="Emitebusiness.Properties.aspnetdbConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" applicationName="/Cfxixi" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="2" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" />
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADMembershipProvider" attributeMapUsername="sAMAccountName" />
</providers>
</membership>
ps.数据库中须有3张表,一张user、一张密码,一张applianciton表,总共三张表