Azure 应用服务上的 Easy Auth 阻止“始终开启”请求

问题描述 投票:0回答:1

我们有一个网络应用程序,在应用程序服务上配置了 Easy Auth,如图所示。因此所有请求都必须获得授权。

screenshot of authentication settings

我们还在网络应用程序上启用了“始终在线”功能,因为我们希望保持底层网站始终处于活动状态。

但是,我们可以在

AppServiceHTTPLogs
日志表中看到,来自
AlwaysOn
用户代理的请求正在接收 401 状态代码。

我们的应用程序没有响应 401,因此 Always On 请求一定被 Easy Auth 功能拒绝。

我查看了这篇文章如何确保“始终开启”应用服务在 Azure AD 后面自动启动,该文章声称将

WEBSITE_WARMUP_PATH
设置为
/
将绕过该 url 的 Easy Auth,但这没有任何改变。此外,我们仍然希望对根的正常请求进行授权,但我们希望允许 Always On 请求实际到达应用程序。

我们如何实现这一目标?

该应用程序是 dotnet,在 Linux 应用程序服务计划上运行(如果这有什么区别的话)。

azure azure-web-app-service azure-authentication
1个回答
0
投票

我创建了一个示例 ASP .Net Web API 应用程序并将其部署到 Azure Web 应用程序 (Linux)。

  • 为了避免该错误,我在应用程序中创建了一个 API 控制器。
  • 感谢@AndyP.dev,我引用了这个doc并在预热方法中添加了
    [AllowAnonymous]
    属性。
  • 这使得始终在线请求能够成功,而不会被 Easy Auth 阻止。

WarmupController.cs

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("api/[controller]")]
public class WarmupController : ControllerBase
{
   requests.
    [AllowAnonymous]
    [HttpGet("warmup")]
    public IActionResult Warmup()
    {
        return Ok("App is warmed up");
    }
}

将应用程序部署到 Azure Web App 后,将环境变量设置为预热路由,如下所示。

enter image description here

这是没有任何错误的输出:

enter image description here

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.