我刚刚将我的项目从 ASP.Net 4.5 迁移到 ASP.Net Core。 我有一个 REST API get 用于返回 blob,但现在返回的是 JSON。
这是旧代码:
[HttpGet]
[ResponseType(typeof(HttpResponseMessage))]
[Route("Download/{documentId}")]
public async Task<HttpResponseMessage> DownloadDocument(string documentId)
{
try
{
var result = await TheDocumentService.DownloadDocument(documentId);
return result;
}
catch (Exception ex)
{
return new HttpResponseMessage
{
StatusCode = HttpStatusCode.InternalServerError,
Content = new StringContent(ex.Message)
};
}
}
除了 [ResponseType(typeof(HttpResponseMessage))]
在 ASP.Net Core 中不起作用外,ASP.net Core 中的代码是相同的,而且两种解决方案中的返回结果也是相同的.
但是当在客户端查看来自服务器的响应时,它们是不同的。
所以它们之间唯一不同的是 [ResponseType(typeof(HttpResponseMessage))]
。 asp.net core 中是否有等效的东西?
最佳答案
Dot Net Core 等价于 [ResponseType(typeof(HttpResponseMessage))]
是 [Produces(typeof(HttpResponseMessage))]
关于c# - ASP.NET Core 中的响应类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48318381/