ASP.NET Core API发送包含在双引号中的字符串

Sam*_*Sam 5 c# asp.net-web-api asp.net-core

我的ASP.NET Core API生成一个SAS要上传到Azure Blob存储的文件.看起来字符串被用双引号括起来,这就是我用来上传文件的前端解决方案的问题.

我怎样才能返回一个字符串,但要确保它不是用双引号括起来的?

这是API控制器:

public async Task<IActionResult> GetSAS(string blobUri, string _method)
{
    if (string.IsNullOrEmpty(blobUri) || string.IsNullOrEmpty(_method))
       return new StatusCodeResult(400);

    // Get SAS
    var sas = _fileServices.GetSAS(blobUri, _method);

    return Ok(sas);
}
Run Code Online (Sandbox Code Playgroud)

Dav*_*idG 6

正如评论中所讨论的,您[Produces]在强制JSON响应的类上有一个属性.从文档上ProducesAttribute我们可以看到它可以应用于动作以及控制器.因此,您可以通过在其中添加特定操作来覆盖它,在您需要text/plain的情况下:

[Produces("text/plain")]
public async Task<IActionResult> GetSAS(string blobUri, string _method)
{
    //snip
}
Run Code Online (Sandbox Code Playgroud)