c# - 在 ASP.NET Core 中使用 MimeMapping

标签 c# asp.net-core-mvc mime-types system.web

我正在尝试将我的旧 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

enter image description here

最佳答案

下面的代码应该可以工作:

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/

相关文章:

c# - ASP.NET Core 在页面上显示数据库中的所有行

c# - 适用于企业应用程序的 ASP.NET Core 1.0

java - 从 struts2 操作多个 contentType 流视频?

c# - NAudio播放IEEEFloat格式

c# - 从 ExecuteMethodCall() 获取枚举

c# - LINQ - 带元素计数的双重分组

c# - dnx 在 Visual Studio Code 上运行 C# 控制台应用程序

asp.net-core-mvc - asp.net 核心中的 AcceptVerbsAttribute

c++ - 在 Windows 上查找文件的 MIME 类型

python - Python pickle 的首选(或最常见)文件扩展名