2015-05-07 26 views
9

我遇到了一個問題,在沒有指定用戶的情況下使用模擬訪問web服務。模擬只在用戶被指定時才起作用

作品: <identity impersonate="true" userName="DOMAIN\USERNAME" password="MyPassword" />

不起作用

<identity impersonate="true" /> 

在調試我用下面的代碼verifiy都使用了正確的域和用戶名,他們是。

System.Security.Principal.WindowsIdentity.GetCurrent().Name; 

這裏比較我的web.config

<authentication mode="Windows" /> 
<identity impersonate="true" /> 
<authorization> 
    <allow users="*" /> 
    <deny users="?"/> 
</authorization> 

我登錄到提示,圖像下面enter image description here

任何想法爲什麼當我指定的用戶只會工作web.config文件?我使用與Domain\Username相同的密碼登錄,並將其輸入<identity impersonate="true" userName="DOMAIN\USERNAME" password="MyPassword" />。我試着用多個帳戶,他們都工作時,我把自己的證件與身份web.config但沒有工作設定爲<identity impersonate="true" />和記錄

編輯 遠程服務器返回錯誤:(403)禁止。同時調試和同時擊中包含它託管在IIS服務器上的服務,我有多個帳戶,他們所有的工作試圖 enter image description here

EDIT 2 一切工作正常。一切都在同一個域

+0

您是否在IIS中啓用匿名身份驗證?嘗試調試此代碼:'System.Web.HttpContext.Current.User.Identity.Name' –

+0

Anonymous當前在IIS中被禁用 – joetinger

+0

我嘗試了您建議的代碼,並且得到了預期的DOMAIN \用戶名。 – joetinger

回答

3

注意以下文字來自https://support.microsoft.com/en-us/kb/306158

Impersonate a Specific User for All the Requests of an ASP.NET Application

To impersonate a specific user for all the requests on all pages of an ASP.NET application, you can specify the userName and password attributes in the tag of the Web.config file for that application. For example: Note The identity of the process that impersonates a specific user on a thread must have the "Act as part of the operating system" privilege. By default, the Aspnet_wp.exe process runs under a computer account named ASPNET. However, this account does not have the required privileges to impersonate a specific user. You receive an error message if you try to impersonate a specific user. This information applies only to the .NET Framework 1.0. This privilege is not required for the .NET Framework 1.1.

To work around this problem, use one of the following methods: Grant the "Act as part of the operating system" privilege to the ASPNET account (the least privileged account).

Note Although you can use this method to work around the problem, Microsoft does not recommend this method. Change the account that the Aspnet_wp.exe process runs under to the System account in the configuration section of the Machine.config file.

,你可以設置Aspnet_wp.exe進程爲您試圖冒充,以獲得所需權限的用戶運行。

這也被討論之前:How do you do Impersonation in .NET?

1

這可能是NTLM雙躍點身份驗證問題。簡而言之,請確保Kerberos SPN已正確設置,以便使用它來代替NTLM。這MSDN博客文章有一個很好的解釋。

http://blogs.msdn.com/b/besidethepoint/archive/2010/05/09/double-hop-authentication-why-ntlm-fails-and-kerberos-works.aspx

另外,基本或表單認證也將實現你希望實現的目標。這是因爲應用程序將擁有用戶的憑據,並且如果配置正確,可以使用它們來訪問後端資源。

您可能還想研究Kerberos委派。它通過它的SPN將第二跳限制在一個資源上。

+0

感謝您的答覆。我還沒有機會嘗試這一點,但在閱讀文章後,它似乎可能是答案 – joetinger

+0

在閱讀了關於設置SPNs https://support.microsoft.com/en-us/kb/929650這將設置應用程序池每次訪問該站點時都使用提供的域/用戶? – joetinger

+0

不需要。從高級設置中,SPN只是一種使用帳戶註冊資源的方法。在這種情況下,您正在註冊用於您的網站的帳戶。這樣,當某人通過Kerberos進行身份驗證時,帳戶可以驗證/解密請求訪問的用戶提供的服務票證。 – user2320464

相關問題