5

Trong ròng 4,5 chúng tôi đang làm việc với proxy như thế này:asp.net lõi defaultProxy

<system.net> 
    <!-- --> 
    <defaultProxy enabled="true" useDefaultCredentials="false"> 
     <proxy usesystemdefault="True" proxyaddress="http://192.168.1.1:8888" bypassonlocal="True" autoDetect="False" /> 
     <module type="CommonLibrary.Proxy.MyProxy, CommonLibrary, Version=1.0.0.0, Culture=neutral" /> 
    </defaultProxy> 

    <settings> 
     <httpWebRequest useUnsafeHeaderParsing="true" /> 
     <servicePointManager expect100Continue="false" /> 
    </settings> 
</system.net> 

nhưng trong asp.net lõi hoặc thử nghiệm, chúng tôi không thể tìm thấy một giải pháp như trên thể một ai đó hãy giúp tôi ?

Tôi thực sự đánh giá cao sự giúp đỡ của bạn

Cảm ơn, Trân trọng

Trả lời

4

Bạn nên sử dụng một trung gian. bạn đã có một cái nhìn tại một này:

https://github.com/aspnet/Proxy

có một thư mục 'mẫu': https://github.com/aspnet/Proxy/tree/dev/samples/Microsoft.AspNetCore.Proxy.Samples

nguồn lực khác về chủ đề này: http://josephwoodward.co.uk/2016/07/proxying-http-requests-asp-net-core-using-kestrel

http://overengineer.net/creating-a-simple-proxy-server-middleware-in-asp-net-core

Liệu một middleware làm việc cho bạn?

+0

Hi. Tôi cần sử dụng defaultProxy bởi vì tôi có một khách hàng wcf mà tôi đang accesing thông qua một proxy với địa chỉ ip xác nhận trên danh sách trắng của nhà cung cấp của tôi. –

4

Để sử dụng một proxy HTTP trong lõi .net, bạn phải thực hiện IWebProxy interface.This là từ System.Net.Primitives.dll assembly.You thể dd nó để project.json nếu chưa có

ví dụ

"frameworks": { 
    "dotnet5.4": { 
     "dependencies": { 
     "System.Net.Primitives": "4.3.0" 
     } 
    } 
} 

thực hiện là rất tầm thường

public class MyHttpProxy : IWebProxy 
    { 

     public MyHttpProxy() 
     { 
      //here you can load it from your custom config settings 
      this.ProxyUri = new Uri(proxyUri); 
     } 

     public Uri ProxyUri { get; set; } 

     public ICredentials Credentials { get; set; } 

     public Uri GetProxy(Uri destination) 
     { 
      return this.ProxyUri; 
     } 

     public bool IsBypassed(Uri host) 
     { 
      //you can proxy all requests or implement bypass urls based on config settings 
      return false; 

     } 
    } 


var config = new HttpClientHandler 
{ 
    UseProxy = true, 
    Proxy = new MyHttpProxy() 
}; 

//then you can simply pass the config to HttpClient 
var http = new HttpClient(config) 

thanh toán https://msdn.microsoft.com/en-us/library/system.net.iwebproxy(v=vs.100).aspx

+0

Cảm ơn bạn nhiều. Làm thế nào tôi có thể làm điều này cho khách hàng wcf? –

+0

Xin chào. Tôi cần sử dụng defaultProxy bởi vì tôi có một khách hàng wcf mà tôi đang accesing thông qua một proxy với địa chỉ ip xác nhận trên danh sách trắng của nhà cung cấp của tôi. –

+0

@MarceloOliveto là bạn đang sử dụng thư viện WCF hướng khách hàng trong lõi .net? trông giống như nó vẫn không hỗ trợ proxy, có một vấn đề được mở cho nó https://github.com/dotnet/wcf/issues/1592 –

Các vấn đề liên quan