试试这个:
<configuration>
<connectionStrings>
<add name="ADService" connectionString="LDAP://mossdc02/, dc=expgroup, dc=ru" />
</connectionStrings>
<system.web>
<membership defaultProvider="AspNetActiveDirectoryMembershipProvider">
<providers>
<add name="AspNetActiveDirectoryMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider,
System.Web, Version=2.0.3600, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADService"
connectionUsername="domain\\userName"
connectionPassword="password"/>
</providers>
</membership>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
<authentication mode="Windows" />
</system.web>
</configuration>
在.cs文件中触发:
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) {
string userName = "domain\\userName";
string password = "password";
if (Membership.Providers["AspNetActiveDirectoryMembershipProvider"].ValidateUser(userName, password)) {
e.Authenticated = true;
}
}
出现此错误:
描述:处理a期间发生错误 服务此请求所需的配置文件。请查看 以下具体错误详细信息并修改您的配置文件 适当。
分析器错误消息:无法加载文件或程序集'System.Web, Version = 2.0.3600,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或 其中一个依赖项。系统找不到指定的文件。
来源错误:
第12行:第13行: type =“System.Web.Security.ActiveDirectoryMembershipProvider,第15行: System.Web,版本= 2.0.3600,文化=中立,第16行:
公钥= b03f5f7f11d50a3a“
请帮助。)
答案 0 :(得分:1)
您不应该创建自己的ActiveDirectoryMembershipProvider
,只应配置有关ActiveDirectoryMembershipProvider
的web.config。
<membership defaultProvider="MyADMembershipProvider">
<providers>
<add
name="MyADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionUsername="testdomain\administrator"
connectionPassword="password"/>
</providers>
</membership>