2013-06-27 59 views
0

我有一個應用程序Web窗體ASP.NET Framework 4.0與c#。 我發佈了它並在IIS(Web服務器)中創建。 當我訪問本網站時,發生錯誤。服務器啓動網站出錯(IIS 7)

我的應用程序池已經設置了Framework 4.0!

錯誤:

無法轉換類型 'System.DirectoryServices.AccountManagement.GroupPrincipal' 的目的爲類型 'System.DirectoryServices.AccountManagement.UserPrincipal'。

在我的home.aspx中,有一個用戶名爲windows的標籤。

protected void Page_Load(object sender, EventArgs e) 
{ 
    string FirstName = UserPrincipal.Current.Surname.ToString(); 
    string LastName = UserPrincipal.Current.GivenName.ToString(); 

    Label1.Text = LastName + " " + FirstName; 
} 

我使用System.DirectoryServices.AccountManagement;

我不能在IIS中使用此身份驗證?在我的本地主機,正常工作

+1

檢查您的應用程序池設置是否正確以使用.Net4框架。 –

+0

理查德。是!我的應用程序池使用Framework 4.0。 – CaioVJesus89

+0

您是否已將網站配置爲模擬經過身份驗證的用戶?否則,UserPrincipal.Current將嘗試返回AppPool標識的信息。 –

回答

0

試試這個:

using System.Web.Hosting; 

protected void Page_Load(object sender, EventArgs e) 
{ 
    using (HostingEnvironment.Impersonate()) 
    { 
     string FirstName = UserPrincipal.Current.Surname.ToString(); 
     string LastName = UserPrincipal.Current.GivenName.ToString(); 
     Label1.Text = LastName + " " + FirstName; 
    } 
} 

還要確保您啓用了Windows身份驗證模式和你的應用程序池正在運行4.0集成。

+0

我正在實施您的建議,但錯誤仍在繼續! ASP.NET模擬/基本身份驗證/匿名身份驗證和Windows身份驗證已啓用,並且AppPool已經設置了框架4.0。 – CaioVJesus89

+0

@ CaioVJesus89您需要禁用匿名身份驗證。請參閱Richard在原始問題 – ovaltein

+0

Steve中的評論。不行。錯誤繼續!我訪問了其他頁面,無需獲取用戶(Windows身份驗證),並且他們正常工作,但非常慢!你有解決方案/建議? TKS! – CaioVJesus89