Content-Disposition 内联在 Chrome 中不起作用
Content-Disposition inline does not work in Chrome
我有一个简单的 asp 网络核心端点,其中 return 电子邮件文件:
[HttpGet("files/{id:int}")]
public async Task<IActionResult> GetFileAsync(int id)
{
...
var fileName = $"{id}.msg";
var filePath = ...;
System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
{
FileName = fileName,
Inline = true,
};
Response.Headers.Add("Content-Disposition", cd.ToString());
return PhysicalFile(filePath, MimeTypes.GetMimeType(filePath));
}
我希望浏览器尝试打开文件并在 Firefox 中运行。但是 Chrome 即使 inline
Content-Disposition
:
也只下载文件
Content-Disposition: inline; filename=10979.msg
Content-Length: 112128
Content-Type: application/octet-stream
Server: Microsoft-IIS/8.5
如何解决这个问题?
How to fix this?
Firefox 帮助用户使用对话框打开文件,但 Edge 和 Chrome 没有。
但是您可以选择 “始终打开这种类型的文件” 选项来自动打开文件。
在 Firefox、Edge 和 Chrome 浏览器
中运行
如何撤消“总是打开这种类型的文件”?
- Chrome
- 边缘
将Content-Type
更改为application/msg
我有一个简单的 asp 网络核心端点,其中 return 电子邮件文件:
[HttpGet("files/{id:int}")]
public async Task<IActionResult> GetFileAsync(int id)
{
...
var fileName = $"{id}.msg";
var filePath = ...;
System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
{
FileName = fileName,
Inline = true,
};
Response.Headers.Add("Content-Disposition", cd.ToString());
return PhysicalFile(filePath, MimeTypes.GetMimeType(filePath));
}
我希望浏览器尝试打开文件并在 Firefox 中运行。但是 Chrome 即使 inline
Content-Disposition
:
Content-Disposition: inline; filename=10979.msg
Content-Length: 112128
Content-Type: application/octet-stream
Server: Microsoft-IIS/8.5
如何解决这个问题?
How to fix this?
Firefox 帮助用户使用对话框打开文件,但 Edge 和 Chrome 没有。 但是您可以选择 “始终打开这种类型的文件” 选项来自动打开文件。
在 Firefox、Edge 和 Chrome 浏览器
中运行
如何撤消“总是打开这种类型的文件”?
如何撤消“总是打开这种类型的文件”?
- Chrome
- 边缘
将Content-Type
更改为application/msg