我正试着把我的旧mvc5项目移到asp net core上。旧代码是:
public string ContentType
{
get
{
if (!string.IsNullOrEmpty(FileName))
return MimeMapping.GetMimeMapping(FileName);
return null;
}
}
错误是
名称'MimeMapping‘在当前上下文中不存在
发布于 2016-03-09 08:24:04
下面的代码应该可以工作:
string contentType;
new FileExtensionContentTypeProvider().TryGetContentType(FileName, out contentType);
return contentType ?? "application/octet-stream";
发布于 2016-09-29 01:50:25
有一个NuGet包MimeTypes,它与.Net核心项目一起工作,作为FileExtensionContentTypeProvider
的替代方案。我不知道有任何其他的mime类型解析器包,它可以与.Net核心一起工作(至少到目前为止)。
用法很简单:
string fileName = "trial.jpg";
string mime = MimeKit.MimeTypes.GetMimeType(fileName);
发布于 2015-12-07 18:32:57
System.Web没有迁移到.NetCore,因为它太依赖于特定于平台的API。你可以看看微软的参考资料:
https://github.com/Microsoft/referencesource/blob/master/System.Web/MimeMapping.cs
该代码受麻省理工学院许可证的约束。
https://stackoverflow.com/questions/34131326
复制相似问题