2009-10-24 119 views
0

我有一個需要Windows集成安全性的ASP.NET應用程序。 出於某種原因,我不想在這裏討論什麼,我需要在運行時創建WebRequest,調用應用程序中的其他頁面並處理結果。ASP.NET + NetworkCredentials,登錄嘗試失敗

該應用程序在我們使用DNS別名的服務器上運行,類似於app.domain.com。

因此,我使用預定義的域用戶名和密碼創建NetworkCredential,並將其附加到請求中。

這就是我得到:

[Win32Exception (0x80004005): The logon attempt failed] 
    System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean throwOnError, SecurityStatus& statusCode) +1404402 
    System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob) +78 
    System.Net.NegotiateClient.DoAuthenticate(String challenge, WebRequest webRequest, ICredentials credentials, Boolean preAuthenticate) +560 
    System.Net.NegotiateClient.Authenticate(String challenge, WebRequest webRequest, ICredentials credentials) +14 
    System.Net.AuthenticationManager.Authenticate(String challenge, WebRequest request, ICredentials credentials) +247 
    System.Net.AuthenticationState.AttemptAuthenticate(HttpWebRequest httpWebRequest, ICredentials authInfo) +243 
    System.Net.HttpWebRequest.CheckResubmitForAuth() +232 
    System.Net.HttpWebRequest.CheckResubmit(Exception& e) +5299747 

[WebException: The remote server returned an error: (401) Unauthorized.] 
    System.Net.HttpWebRequest.GetResponse() +5313085 
    Entropy.Envoy.Web.Corporate.ExportFilter.GetTargetReportContent(Uri targetUrl, HttpCookieCollection cookies) +521 
    Entropy.Envoy.Web.Corporate.ExportFilter.Page_Load(Object sender, EventArgs e) +139 
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 
    System.EventHandler.Invoke(Object sender, EventArgs e) +0 
    System.Web.UI.Control.OnLoad(EventArgs e) +99 
    System.Web.UI.Control.LoadRecursive() +50 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627 

相同的代碼工作在其他服務器上使用類似的設置雖然。 發生了什麼事?

回答

0

找到了答案。 原來如同將Active Directory添加到SPN一樣簡單:

setspn -a HTTP//WebServer.domain.com customDomainAccount 
setspn -a HTTP//servername customDomainAccount