2009-09-10 19 views
2

我正在開發一個ActiveDirectoryMembershipProvider和SqlProfileProvider的asp.net intranet網站。ProfileProvider:檢索所有配置文件的列表

我的網站的一個要求是有一個「生日」頁面,這將需要我列出所有配置文件並從中檢索生日信息。

我走近問題如下:

  • 調用Membership.GetAllUsers()靜態方法;
  • 迭代通過用戶的列表,並檢索從會員的用戶名

這種方法的輪廓,然而,失敗的原因如下:

  • web應用程序正在模擬當前登錄用戶檢索其AD詳細信息(身份impersonate =「true」在web.config中),所以當我試圖調用GetAllUsers時出現異常「訪問被拒絕」如果我試圖讓webapp模擬一個超級用戶帳戶那麼AD將用戶名作爲username @ domain-name返回格式,但在我的配置文件提供程序中,它們最初以域名\用戶名格式存儲。

那麼,你將如何解決這個問題來檢索組織的任何成員的配置文件的整個列表?

回答

2

雖然我以前從未做過,但可以嘗試創建第二個模擬上下文,該模擬在建立時調用GetAllUsers應成功。

看看http://chiragrdarji.blogspot.com/2007/03/impersonation-using-code.html,本章似乎已通過使用System.Security.Principal.WindowsIdentity類和System.Security.Principal.WindowsImpersonationContext一起實現了安全上下文中的更改。可能值得一試。

1
ProfileInfoCollection profiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All); 
foreach (ProfileInfo pi in profiles) 
{ 
    ProfileCommon p = Profile.GetProfile(pi.UserName); 
    countries.Add(p.Country);   
} 
相關問題