Azure App Service 未经授权的用户访问控制器

Azure App Service Unauthorised user access to controller

我有一个脚本可以在用户通过身份验证时正常工作:

[MobileAppController]
public class TestController : ApiController
{
// GET api/Test
[HttpGet, Route("api/Test/completeAll")]
public string Get()
{
    MobileAppSettingsDictionary settings = this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings();
    ITraceWriter traceWriter = this.Configuration.Services.GetTraceWriter();

        string host = settings.HostName ?? "localhost";
        string greeting = "Hello from " + host;

        traceWriter.Info(greeting);
        return greeting;
    }

    // POST api/values
    [HttpPost, Route("api/Test/completeAll")]
    public string Post(string hej)
    {
        string retVal = "Hello World!" + hej;
        return retVal;
    }
}
}

可以看出,我没有添加属性 [Authorize],这是要求身份验证的新方式,see controller on this link。并且在同一个 link 中声明控制器现在是匿名的。

但是,如果我在身份验证之前尝试访问控制器,我会被拒绝访问,但在身份验证之后它可以正常工作。

谁能澄清一下?

更新

根据 this link 我不应该更改任何东西,因为安装了 quickstart。它仍然有效:/

您是否将 Azure 应用服务身份验证/授权设置为要求对所有请求进行身份验证?

  • 转到 Azure 门户中的应用服务
  • 所有设置 -> 身份验证/授权(在功能下)
  • 在"Action to take when request is not authenticated"下,设置为"Allow request (no action)"

这将使应用程序控制授权而不是服务。