小编Tom*_*ana的帖子

Azure Function,返回状态码+JSON,没有在每一部分逻辑中定义return

我有一个 Azure Function 2.x,它驻留在一个看起来像这样的静态类上

[FunctionName("Register")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequest req, ILogger log)
{
    MyTypeClass defReturn = new MyTypeClass();
    HttpStatusCode defCode = HttpStatusCode.BadRequest;

    /*
    * Logics that might or might not changes
    * defReturn and defCode value
    */

    return StatusCode((int) defCode, JsonConvert.SerializeObject(defReturn))
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现这个return StatusCode((int) defCode, JsonConvert.SerializeObject(defReturn))部分?Azure Functions 2.x 中是否有任何此类方法或等效方法?

在 Azure Functions 1.xi 中可以做等效的req.CreateResponse(defCode, defReturn)where reqis HttpRequestMessage,但我试图坚持使用 2.x 模板/标准

附加说明:所述代码应将HTTP 400 Bad RequestdefReturn作为响应正文返回给客户端。但是,当我改变defCodeHttpStatusCode.Accepted,它应该返回HTTP …

c# azure azure-functions asp.net-core-2.1

13
推荐指数
1
解决办法
1万
查看次数

在.NET应用程序中关闭MySQL连接是否很重要?(确切地说,C#)

人们在早期使用MySQL时所学到的一些事情,即在使用后立即关闭连接很重要,但为什么这么重要呢?那么,如果我们做一个网站,它可以节省一些服务器资源(如描述在这里),但为什么我们应该做的是在.NET桌面应用程序?它是否与Web应用程序共享相同的问题?或者还有其他人吗?

.net c# mysql mysql-connector

4
推荐指数
1
解决办法
1249
查看次数