问题
Try this:
<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>
In .cs file fire this:
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;
}
}
Have this error:
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'System.Web, Version=2.0.3600, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Source Error:
Line 12: Line 13: type="System.Web.Security.ActiveDirectoryMembershipProvider, Line 15: System.Web, Version=2.0.3600, Culture=neutral, Line 16:
PublicKeyToken=b03f5f7f11d50a3a"
Help please.)
回答1:
You should not create your own ActiveDirectoryMembershipProvider
, you shall only config the web.config regarding the ActiveDirectoryMembershipProvider
.
<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>
来源:https://stackoverflow.com/questions/22220803/error-in-web-config-with-membership-ad-provider