Kerberos委托方案中的ASP双跳请求

问题描述:

请帮忙! 我需要我的asp应用程序来请求具有模拟用户凭据的远程系统。但总是得到401未经授权的错误。 我从这里进行了所有配置:https://support.microsoft.com/en-us/help/810572/how-to-configure-an-asp-net-application-for-a-delegation-scenario Kerberos配置和工作在我的应用程序和我的测试远程应用程序(我看到小提琴手kerberos门票)。委派,spns和一切都已配置。Kerberos委托方案中的ASP双跳请求

这就是我的代码usnig System.Net.Http.httpclient:

HttpClientHandler handler = new HttpClientHandler() 
{ 
    UseDefaultCredentials = true, 
    PreAuthenticate = true 
}; 

using (HttpClient client = new HttpClient(handler)) 
{ 
    client.DefaultRequestHeaders.Accept.Clear(); 
    var method = new HttpMethod("GET"); 
    var request = new HttpRequestMessage(method, "http://testdelegationapp.avp.ru/"); 
    var response = client.SendAsync(request).Result; 
} 

其实HTTP请求是由应用程序池帐户进行(限制访问的应用程序池帐户在远程应用程序IIS,当我得到401错误)

这里:How to get HttpClient to pass credentials along with the request? 声称的HttpClient着传递安全令牌到另一个线程,而其更好的使用Web客户端使用System.Net.WebClient

代码的同步方法:

var wi = (WindowsIdentity)HttpContext.User.Identity; 
var wic = wi.Impersonate(); 
try 
{ 
    string URI = "http://testdelegationapp.avp.ru/"; 
    using (WebClient wc = new WebClient()) 
    { 
     wc.UseDefaultCredentials = true; 
     string response = wc.DownloadString(URI); 
    } 
} 
finally 
{ 
    wic.Undo(); 
} 

结果更差,同样的401错误,但在提琴手我可以看到,使用NTLM票证的webclient获得远程应用程序!

配置流动的令牌从这里抛出线程:Unable to authenticate to ASP.NET Web Api service with HttpClient 也不帮助。 SecurityContext.IsWindowsIdentityFlowSuppressed()为false。

WindowsIdentity.GetCurrent()。Name和Thread.CurrentPrincipal.Identity.Name显示模拟用户,因为它应该是。

所有的时间问题是在Chrome浏览器中,默认情况下,它prohobits kerberos委派。您768,16以下添加到注册表:

Path: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome ; 
string: AuthNegotiateDelegateWhitelist ; 
value: *.avp.ru 

所以,现在我的工作方案是

HttpClient的Web请求。

如果要在 委托凭证中执行所有应用程序,则在IIS中启用ASP模拟。如果你想方法具体代表团,然后使用:

var wi = (WindowsIdentity)HttpContext.User.Identity;  
var wic = wi.Impersonate(); 
wic.Undo(); 

的HttpClient在另一个线程执行的请求,所以在aspnet_config.config我们需要以下变化:

<legacyImpersonationPolicy enabled="false"/> 
<alwaysFlowImpersonationPolicy enabled="true"/> 

你可以找到aspnet_config.config:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config 
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet.config 
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet.config 
+0

这种情况下使用的客户端操作系统是什么? –

+0

@ T-Heron Windows 10 – Gunman7840