2013-07-02 12 views
2

我在IIS8(windows server 2012)上設置了一個新的asp.net站點。我試圖採用適用於Windows Server 2008,IIS6的舊代碼。兩者都是虛擬服務器。asp.net應用程序識別本地主機上的用戶,但不在服務器上,沒有硬編碼用戶名/密碼

啓用Windows身份驗證。

匿名身份驗證被禁用。

(每一些後我看了,但沒有改變試圖使)通過獲取用戶:

的System.DirectoryServices:

string user = System.Web.HttpContext.Current.User.Identity.Name; 

int separatorIndex = user.LastIndexOf(@"\"); 
if (separatorIndex != -1 && separatorIndex < user.Length - 1) 
    { 
    user = user.Substring(separatorIndex + 1); 
    } 

DirectoryEntry rootEntry = new DirectoryEntry("LDAP://na.xxxxxx.biz"); 

DirectorySearcher directorySearcher = new DirectorySearcher(rootEntry); 
directorySearcher.Filter = string.Format("(&(objectClass=user)(objectCategory=user) (sAMAccountName={0}))", user); 
directorySearcher.PropertiesToLoad.Add("displayName"); 

var result = directorySearcher.FindOne(); 

這工作在本地主機上很大,在服務器上返回一個錯誤.DirectoryServicesCOMException(0x80072020):發生操作錯誤。 System.DirectoryEntry.Bind(Boolean throwIfFail)在System.DirectoryServices.DirectoryEntry.Bind()在System.DirectoryServices.DirectoryEntry.get_AdsObject()在System.DirectoryServices.DirectorySearcher.FindAll(布爾findMoreThanOne)在System.DirectoryServices.DirectorySearcher .FindOne()在EngApps.App_Code.UserFullName.LookUpDirectory()中E:\的Inetpub \ wwwroot的\ App_Code文件\ UserFullName.cs:線45

線45是我以上使用「FindOne造成的最後一行() 「

如果我硬編碼我的用戶名和密碼,一切工作在服務器上:

rootEntry.Username = user; 
rootEntry.Password = "xxxxxx"; 

但我不需要在舊的代碼庫中,所以我猜在IIS8中有一個設置。我玩了一下匿名認證,閱讀了幾篇文章,但還沒有弄清楚。

感謝您的幫助。

回答

3

問題很可能是您的應用程序運行的IIS應用程序池的身份是沒有權限查詢域,如LocalService。

您應該檢查先前實例上的應用程序池,並確保身份相同或至少具有相似的訪問能力。

+0

這工作,感謝您的快速答案! –

相關問題