我的 ASP.NET Core API 为要上传到 Azure Blob 存储的文件生成 SAS
。看起来字符串用双引号引起来,这对我用来上传文件的前端解决方案造成了问题。
我怎样才能返回一个字符串,但要确保它没有用双引号引起来?
这是 API Controller :
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);
}
最佳答案
正如评论中所讨论的那样,您在强制 JSON 响应的类上有一个 [Produces]
属性。来自docs on ProducesAttribute
我们可以看到它可以应用于 Action 以及 Controller 。因此,您可以通过在此处添加特定操作来覆盖它,在您的情况下您需要 text/plain :
[Produces("text/plain")]
public async Task<IActionResult> GetSAS(string blobUri, string _method)
{
//snip
}
关于c# - ASP.NET Core API 发送用双引号引起来的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48009890/