我正在尝试将我的旧 mvc5 项目移动到 asp net core。 旧代码是:
public string ContentType
{
get
{
if (!string.IsNullOrEmpty(FileName))
return MimeMapping.GetMimeMapping(FileName);
return null;
}
}
错误是
The name 'MimeMapping' does not exist in the current context
最佳答案
下面的代码应该可以工作:
string contentType;
new FileExtensionContentTypeProvider().TryGetContentType(FileName, out contentType);
return contentType ?? "application/octet-stream";
关于c# - 在 ASP.NET Core 中使用 MimeMapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34131326/