我正在尝试将我的旧mvc5项目移动到mvc6.旧代码是:
public string ContentType
{
get
{
if (!string.IsNullOrEmpty(FileName))
return MimeMapping.GetMimeMapping(FileName);
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
错误是
当前上下文中不存在名称"MimeMapping"
我刚刚将项目从 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)
};
}
}
Run Code Online (Sandbox Code Playgroud)
ASP.net Core 中的代码除了[ResponseType(typeof(HttpResponseMessage))]在 ASP.Net Core 中不起作用之外是相同的,并且两种解决方案的返回结果也相同。
但是当在客户端查看服务器的响应时,它们是不同的。
因此,它们之间唯一的区别是[ResponseType(typeof(HttpResponseMessage))]. ASP.NET Core 中有类似的东西吗?