【问题标题】:Blazor Server App on Azure: AuthenticationException: The remote certificate is invalid according to the validation procedureAzure 上的 Blazor Server App:AuthenticationException:根据验证过程,远程证书无效
【发布时间】:2021-04-09 08:39:23
【问题描述】:

我正在使用 VS2019 开发 Blazor 服务器应用程序。在本地运行(调试或发布)时,它正在运行并且工作正常。将其发布到 Azure App Services 后,我收到远程证书无效消息。目前我调用了一个控制器方法。

如果剃刀页面代码为:

protected override async Task OnParametersSetAsync()
{
    await Task.Run(async () => await GetExperimentInfo());
}

protected async Task GetExperimentInfo()
{
    if (string.IsNullOrEmpty(eid))
    {
        ExperimentName = "Experiment entity not provided";
        return;
    }

    HttpClient client = new HttpClient();
    client.BaseAddress = new Uri(NavigationManager.BaseUri);

    ExpInfo = await client.GetFromJsonAsync<ExperimentInfo>("api/experiment/" + eid);
    if (ExpInfo == null)
    {
        ExperimentName = "Error: Experiment not found";
        return;
    }

    ExperimentName = ExpInfo.Name;
}

“eid”被指定为调用剃须刀页面的参数。

在 Azure App Service 上的服务器应用中调用控制器 GET 方法时,直接返回正确的信息。 从 razor 页面调用相同的控制器 GET 方法返回无效远程证书的 AuthenticationException!

控制器中调用的方法是:

    [Route("api/experiment/{eid}")]
    [HttpGet]
    public ExperimentInfo GetExperimentInfo(string eid)
    {
        var ExpInfo = GetSNExperimentData(eid);

        return ExpInfo;
    }

我在网上浏览了很多文章,但到目前为止没有找到正确的答案为什么以及如何解决这个问题。

任何人有任何想法或经验吗?谢谢

【问题讨论】:

  • 正如错误所说,HttpClient 抱怨该 https 端点上的证书无效。您可以自己查看证书并验证证书是否已过期/是否有其他问题。
  • 有时也可能发生证书有效但不受服务器信任的情况。 (即证书是自签名的,或者从您的服务器的角度来看,证书颁发者不是“受信任的”方。另一个解决方法记录在另一个 stackoverflow 问题中:stackoverflow.com/questions/777607/…

标签: c# azure blazor-server-side azure-webapps


【解决方案1】:

Microsoft Azure 支持(Kevin Kessler)解决了这个问题,并给出了以下解释:

这表明远程 Web 服务的证书链中的任何根 CA 都是不受信任的。这是由于根 CA 未包含在应用服务的受信任根存储中。

Azure Web 应用驻留在应用服务环境 (ASE) 上。在这种情况下,您可以通过上传所需的证书并将其指纹值分配给应用服务设置来解决问题。

请参阅此文档,其中介绍了在 ASE 上使用证书以及如何在应用服务上进行配置: https://docs.microsoft.com/en-us/azure/app-service/environment/certificates#private-client-certificate

此外,这篇 StackOverflow 文章可能会提供进一步的指导: How to make the azure app service trust the certificates issued by the OnPrem CA?

解决方案:已将根证书和中间证书上传到 ASE

【讨论】:

    猜你喜欢
    • 2011-03-28
    • 2016-11-28
    • 2017-09-19
    • 2013-08-08
    • 2012-07-20
    • 2015-03-17
    • 2021-05-30
    相关资源
    最近更新 更多