【问题标题】:Azure function deployed with Dotnet 6 from Visual Studio 2022 doesn't work使用 Visual Studio 2022 中的 Dotnet 6 部署的 Azure 功能不起作用
【发布时间】:2022-01-18 10:38:45
【问题描述】:

所以我有一个基本的功能。代码如下所示。我可以在本地运行它而没有任何问题。我可以从浏览器和邮递员调用它。但是当我对 Azure Functions 运行基本部署时,它说部署成功,但我无法从浏览器或邮递员调用它。我记得要创建函数 AuthorizationLevel.Anonymous,所以我不必包含 apikey 或任何身份验证。

我已尝试将此功能部署到多个区域以及 Windows 和 Linux 功能。

https://someawesomefunction20211215085831.azurewebsites.net/api/Swag

http://localhost:7071/api/Swag

*编辑:

添加了 prod 的 GIF,不适用于 Visual Studio 部署的默认设置。

我部署的功能没有显示在功能概览中???会不会是这个问题?

public static class Awesomeness
{
    [FunctionName("Swag")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        string name = req.Query["name"];

        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);
        name = name ?? data?.name;

        string responseMessage = string.IsNullOrEmpty(name)
            ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
            : $"Hello, {name}. This HTTP triggered function executed successfully.";

        return new OkObjectResult(responseMessage);
    }
}

【问题讨论】:

  • 我们在本地环境中对此进行了测试,在 Visual Studio 2022 中使用 .net 6 创建了一个简单的 http 触发函数。我们能够在本地和门户中使用 .net6 的 postman 触发 http 函数也是。 1.我们从local through postman触发函数时的参考图像。 2. 触发同一个Http函数hosted on Azure时的参考图。
  • 我刚刚创建了一个新项目。使用默认设置部署它。但我永远不能在天蓝色上调用它。添加了显示默认设置和所有设置的 gif。
  • @VenkateshDodda-MT > 您的屏幕截图显示您可以在门户中查看/测试您的 Azure 功能。我没有在该概述中看到我的 Azure 函数。只有上面的 AppService。
  • @Kiksen- 让我们加入这个聊天室进一步讨论chat.stackoverflow.com/rooms/info/240170/…
  • 您能否确认您使用的是 Azure Functions 运行时 v4.0?

标签: .net azure .net-core azure-functions


【解决方案1】:

关闭解决方案并在 Visual Studio 2022 中再次打开后,问题得到解决。建议他们在将函数从本地发布到 Azure 函数应用时启用从包文件运行。发布该用户能够在函数应用程序下看到该函数,并且也能够从邮递员那里触发该函数。

【讨论】:

    猜你喜欢
    • 2018-12-20
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 2023-01-11
    • 2014-10-01
    • 2022-10-17
    • 2022-12-13
    相关资源
    最近更新 更多