我如何使用自己的自定义AuthorizationLevel在azure中运行函数?

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

我已经在Azure中发布了具有功能的AuthorizationLevel的功能应用程序。所以我访问用户需要用户提供密钥的端点。我可以更改它以便拥有自己的密钥吗?我在应用程序中使用的代码是

        [FunctionName("MyFunction")]
        public static async Task<IActionResult> Run(
        [HttpTrigger(**"myownazurekey"**, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {   .....

所以我可以将myownazurekey设置为azure而不是使用定义的主/默认密钥吗?

c# azure asp.net-core
1个回答
0
投票

您的代码中不需要**"myownazurekey"**,。您可以按照我的步骤来创建自定义密钥,以访问功能应用程序。

  1. 在门户网站中创建功能应用程序。

  2. 转到资源,找到Functions -> App Keys -> + New host key,然后输入名称custonkey和值0510wxwc

  3. 部署您的功能应用程序。

    示例功能代码:

    [FunctionName("MyFunction")]
    public static async Task<IActionResult> Run1([HttpTrigger("get", "post", Route = null)] HttpRequest req,ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
    
        string name = req.Query["test"];
    
        return new OkObjectResult(name);
    }
    
  4. 从门户复制类似图片的网址

enter image description here

  1. 邮递员测试。

enter image description here

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