2014-03-06 73 views
0

web.config中試試這個:錯誤與會員AD提供商

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

有此錯誤:

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"

請幫助。 )

回答

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> 
+0

不明白。此代碼與我的代碼類似。 – mathewsun

+0

版本應該是2.0.0.0,但不是2.0.3600。好。謝謝! – mathewsun

+0

我的實際懷疑是正確的關於GAC :) –