0

尝试这个:

<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;
            }
        }

有这个错误:

说明:处理服务此请求所需的配置文件期间发生错误。请查看下面的具体错误详细信息并适当地修改您的配置文件。

解析器错误消息:无法加载文件或程序集“System.Web,版本=2.0.3600,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。该系统找不到指定的文件。

源错误:

第 12 行:第 13 行:type="System.Web.Security.ActiveDirectoryMembershipProvider,第 15 行:System.Web,版本=2.0.3600,Culture=neutral,第 16 行:
PublicKeyToken=b03f5f7f11d50a3a"

请帮忙。)

4

1 回答 1

1

你不应该创建你自己的ActiveDirectoryMembershipProvider,你应该只配置关于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>
于 2014-03-06T10:07:44.523 回答