2013-07-10 85 views
0

第一次嘗試在ASP.NET Web應用程序中使用AD身份驗證。當試圖通過使用ActiveDirectoryMembershipProvider類我得到一個錯誤,說明The Active Directory Membership Provider has not been initialized.嘗試訪問用戶信息時尚未初始化Active Directory成員資格提供程序

這裏獲取有關用戶的基本信息是我的web.config:

<connectionStrings> 
     <add name="ADService" connectionString ="LDAP://AMAZON-A923C5B1.l5.chm.com/" /> 
    </connectionStrings> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 

    <membership defaultProvider="AspNetActiveDirectoryMembershipProvider"> 
     <providers> 
     <add name="AspNetActiveDirectoryMembershipProvider" 
      type="System.Web.Security.ActiveDirectoryMembershipProvider, 
       System.Web, Version=2.0.3600, Culture=neutral, 
       PublicKeyToken=b03f5f7f11d50a3a" 
      connectionStringName="ADService"/> 
     </providers> 
    </membership> 

這裏是我的代碼:

ActiveDirectoryMembershipProvider provider = new ActiveDirectoryMembershipProvider(); 

    if (this.Page.User.Identity.IsAuthenticated) 
    { 

     MembershipUser user = provider.GetUser(this.Page.User.Identity.Name, true); 

     LoginName loginName = HeadLoginView.FindControl("HeadLoginName") as LoginName; 
     loginName.FormatString = user.UserName; 
    } 
} 

這是我的錯誤:

enter image description here

回答

0
provider.Initialize("NameOfYourProvider", NameValueCollectionOfConfigOptions) 

其中「NameValueCollectionOfConfigOptions」是NameValueCollection

+2

根據MSDN,「此方法不打算從您的代碼中調用」。 http://msdn.microsoft.com/en-us/library/system.web.security.activedirectorymembershipprovider.initialize.aspx –

0

您正在尋找的課程是System.Web.Security.Membership。該課程將GetUser作爲靜態成員公開。我不認爲ActiveDirectoryMembershipProvider類是爲了直接使用。從文檔,

This class is used by the Membership and MembershipUser classes to provide membership services for an ASP.NET application using an Active Directory (AD) or Active Directory Application Mode (ADAM) server.

相關問題