string contentType;
new FileExtensionContentTypeProvider().TryGetContentType(FileName, out contentType);
return contentType ?? "application/octet-stream";
FileExtensionContentTypeProvider
的替代品,用于 .Net Core 项目。据我所知,目前没有其他可以与 .Net Core 兼容的 mime-type 解析器包。string fileName = "trial.jpg";
string mime = MimeKit.MimeTypes.GetMimeType(fileName);
Microsoft.AspNetCore.StaticFiles
已经被弃用,这是一个更好的解决方案。 - HackSlashMicrosoft.AspNetCore.StaticFiles
已经被弃用,这是一个更好的解决方案。 - undefinedSystem.Web没有被迁移到.NetCore,因为它过于依赖特定于平台的API。您可以查看微软参考源代码:
https://github.com/Microsoft/referencesource/blob/master/System.Web/MimeMapping.cs
该代码受MIT许可证保护。