NET Core 2.2 - HttpClient и Windows Identity, отсутствует сборка - PullRequest
0 голосов
/ 11 октября 2019

Я создаю ASP.NET Core HTTP API (2.2), который должен вызывать другой веб-сервис с использованием олицетворенной учетной записи.

Ссылки в моем проекте следующие:

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" />
    <PackageReference Include="Microsoft.Windows.Compatibility" Version="3.0.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" />    
  </ItemGroup>

И вот код, который я использую для вызова веб-клиента:

var windowsIdentity = new WindowsIdentity(user.UserPrincipalName);
var windowsIdentity = new WindowsIdentity(user.UserPrincipalName);
WindowsIdentity.RunImpersonated(windowsIdentity.AccessToken, () => {
    var impersonatedUser = WindowsIdentity.GetCurrent();
    Console.WriteLine(impersonatedUser.Name);

    using(HttpClient client = new System.Net.Http.HttpClient(new HttpClientHandler() { Credentials = CredentialCache.DefaultCredentials })) 
    {                        
        var result = client.GetAsync("https://.../_api/web/currentUser").Result;
        Console.WriteLine(result);
    }

});

Если я использую HttpClient , я получаю эту ошибку времени выполнения:

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.IO.FileLoadException:
File name: 'System.Net.Security, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at System.Net.Http.SocketsHttpHandler.get_SslOptions
   at System.Net.Http.HttpClientHandler.set_ClientCertificateOptions(ClientCertificateOption value)
   at System.Net.Http.HttpClientHandler..ctor(Boolean useSocketsHttpHandler)
   at System.Net.Http.HttpClientHandler..ctor()

Почему он ищет NET-зависимость?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...