【发布时间】:2017-12-07 15:30:04
【问题描述】:
我在使用 .NET Core 1.1 Web 应用程序使用 HTTPS (TLS 1.2) 对外部 API 进行 HTTP 调用时遇到问题。该应用程序在本地运行良好,但在部署到 Azure 应用服务时出现以下异常:
exceptionMessage:An error occurred while sending the request.
exceptionType:System.Net.Http.HttpRequestException
内部异常是:
innerExceptionMessage:A security error occurred
innerExceptionType:System.Net.Http.WinHttpException
奇怪的是,我并没有在对外部 API 的所有请求上都收到此异常,它只会发生几次。
我注意到其他 SO 帖子中也讨论了类似的问题,但大部分都是关于自签名证书的。就我而言,远程服务器使用的是 GeoTrust 签名的证书。
所有电话都使用System.Net.Http.HttpClient进行
相关:
- Asp.Net Core: Calling another REST-Api throws WebException
- .net core API Post exception gives NativeErrorCode 12175
- HTTPS request fails using HttpClient
- Security Error, post with Client Certificate (Self-signed Root) on Azure (Asp.net core)
完整的堆栈跟踪:
{ exceptionType: "System.Net.Http.HttpRequestException", innerException: { innerStacktrace: " at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()", innerExceptionMessage: "A security error occurred", innerExceptionType: "System.Net.Http.WinHttpException" }, stacktrace: " at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.ApiService.<PostResourceToApiAsync>d__5`1.MoveNext() in C:\projects\integration\src\Integration\Services\ApiService.cs:line 112 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.AccountService.<NotifyOwnerAsync>d__12.MoveNext() in C:\projects\integration\src\Integration\Services\AccountService.cs:line 115 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.AccountService.<CreateAccountAsync>d__9.MoveNext() in C:\projects\integration\src\Integration\Services\AccountService.cs:line 66 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.PartnerService.<CreateAccountAsync>d__11.MoveNext() in C:\projects\integration\src\Integration\Services\PartnerService.cs:line 100 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Controllers.AccountsController.<Create>d__7.MoveNext() in C:\projects\integration\src\Integration\Controllers\AccountsController.cs:line 92 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextExceptionFilterAsync>d__24.MoveNext()", exceptionMessage: "An error occurred while sending the request." }
【问题讨论】:
-
你也能得到堆栈跟踪吗?另外,如果可能,请尝试进行 [system.net 跟踪](docs.microsoft.com/en-us/dotnet/framework/network-programming/…)
-
我已经添加了完整的堆栈跟踪,但我还没有让 system.net 跟踪工作。
-
请按此开启system.net追踪blogs.msdn.microsoft.com/benjaminperkins/2017/01/05/…
-
我遵循了该指南,但没有文件写入
initializeData属性中指定的目录。也许文章中描述的方法不适用于 .NET Core 应用程序。 -
这可能是对的,我还没有尝试过.net核心应用程序。我会检查它并更新这个线程
标签: azure asp.net-core tls1.2 asp.net-core-1.1