发布函数时未返回 Azure Functions V2 Http 错误代码内容

标签 azure azure-functions

我正在使用 Azure Functions V2,在 Visual Studio 2017 中进行开发。我想返回函数返回的 HTTP 错误代码的自定义内容。当我在本地测试时,这效果很好。但是当我将函数发布到Azure时,不再返回自定义内容。

这很容易重现。这是一个函数(从 VS 2017 Azure Function 新项目模板中提取):

using System;
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;

namespace FunctionApp1
{
    public static class Function1
    {
        [FunctionName("StatusCodeTest")]
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequest req, TraceWriter log)
        {
            return new NotFoundObjectResult("Sample content text.");
        }
    }
}

在本地运行并从 Postman 发出 Post 或 Get。它将返回 404 Not Found 状态代码并显示“示例内容文本”的响应正文。

将函数发布到 Azure 并在那里调用它 - 通过 Postman 或使用 Azure 门户的测试或运行功能。仍然返回 404,但自定义输出被通用消息替换:“您正在查找的资源已被删除、名称已更改或暂时不可用。”

其他 ...ObjectResult 状态代码的行为相同,例如 BadRequestObjectResult 等。

如何发布或配置我的函数以使其返回自定义错误状态内容?

最佳答案

这是最新 Functions v2 运行时 (2.0.11888) 中的回归。请参阅https://github.com/Azure/app-service-announcements/issues/117了解更多详细信息和解决方法。

更一般地说,请遵循此存储库以确保您收到所有通知。

关于发布函数时未返回 Azure Functions V2 Http 错误代码内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51141746/

相关文章:

azure - 如何在azure中调用预定的webjob?

azure - 将 Azure Functions(Linux 托管)从消费计划移至高级计划

.net - 动态调整Azure App Service的系统时间

c# - Azure Function 上的 HttpRequest 不适用于 https

azure - Azure 计算将事件推送到 Azure EventGrid 时是否很慢?有没有办法更快地获取事件?

azure - 管理 Azure Functions 中的 SQL 连接

azure - 从 Azure 函数运行容器的最佳方法

python - 尝试验证任何 ARM 模板,但收到 : 'Error converting value <...MyTemplate...> to type ' . ...Templates.Schema.Template'

c# - Azure Web应用程序授权: session variables for auth/me

Azure 消费 API 非常慢