解决方法
获取文件扩展名,并在注册表中查找.它的条目将具有“内容类型”属性.
这是从控制器操作返回FilePathResult的完整示例:
string filePysicalPath,fileName; //these need to be set to your values. var reg = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey( Path.GetExtension( filename ).ToLower() ); string contentType = "application/unknown"; if ( reg != null ) { string registryContentType = reg.GetValue( "Content Type" ) as string; if ( !String.IsNullOrWhiteSpace( registryContentType ) ) { contentType = registryContentType; } } return File( filePysicalPath,contentType,filename );