第一次嘗試在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;
}
}
這是我的錯誤:
根據MSDN,「此方法不打算從您的代碼中調用」。 http://msdn.microsoft.com/en-us/library/system.web.security.activedirectorymembershipprovider.initialize.aspx –