簡體   English   中英

TLS 1.1和1.2的連接問題-Azure Web應用

[英]Connection issue with TLS 1.1 and 1.2 - Azure web app

在我的應用程序中,我正在從另一個WebAPI方法(理想情況下是內部服務調用)中調用用WebAPI編寫並托管在PaaS環境中的API,該方法是藍色的,例如,WebApp_A中的MethodA調用WebApp_B中的MethodB。 但是,如果WebApp_B的TLS設置為1.1或1.2(它與1.0兼容),我會遇到上述錯誤。 “無法從傳輸連接讀取數據:遠程主機強行關閉了現有連接。”

我有類似的WebApp(WebApp_C),它沒有TLS錯誤。 下面是我們用來從WebApp_A調用WebApp_B中的MethodB的代碼

 public async Task<ServiceResponse> CreateDialog(RequestObject requestObject)
 {
        ServiceResponse serviceResponse = new ServiceResponse();
        try
        {
            using (var client = new HttpClient())
            {

                SessionTokenBo jwtData = new SessionTokenBo();
                Logger = _logger;
                jwtData = GetInternalToken(InternalCallTypes.Utilities.ToString(), int.Parse(ServiceConfiguration.TokenExpiryWindow), int.Parse(ServiceConfiguration.InternalTokenExpiryWindow));
                if (null != jwtData)
                {
                    client.BaseAddress = new Uri("URI");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtData.Token);                        HttpResponseMessage response = await client.PostAsJsonAsync("service/methodB", requestObject);                        
                    if (response.IsSuccessStatusCode)
                    {
                        var data = response.Content.ReadAsStringAsync().Result;
                        serviceResponse = JsonConvert.DeserializeObject<ServiceResponse>(data);
                    }
                }
            }
        }
        catch (Exception ex)
        {
           throw
        }
        return serviceResponse;
  }

如果我這樣給出安全協議,它將起作用

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

我也嘗試從郵遞員的請求,它沒有失敗。 所以現在很困惑,因為如果郵遞員工作,那么理想情況下不是WebApp設置問題

TLS 1.0不再是默認值。 在發出請求之前添加以下行:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

請參考此問題

更新:

但是我的疑問是,為什么其他Web應用程序不能使用相同的代碼?

發現了問題,這是由於webconfig中的目標框架是4.5.2。

<compilation targetFramework="4.7.2"></compilation> 
<httpRuntime targetFramework="4.7.2" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM