我正在尝试编写一个 WebAPI 控制器,它可以动态生成 Windows 快捷方式文件 (.lnk) 并将其发送回客户端,但即使我在 Content-Disposition 标头中指定“.lnk”作为扩展名构建响应时,Chrome 仍会在“另存为”对话框中将其更改为“.download”。我尝试过使用 application/x-ms-shortcut 和 application/octet-stream 作为内容类型,但在这两种情况下它具有相同的行为。
有谁知道如何避免这种情况并强制它在对话框中建议“Link.lnk”?
注 1:我使用的是 Chrome 47.
注2:在IE 11中运行良好.
var response = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(linkPath, FileMode.Open);
response.Content = new StreamContent(stream);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "link.lnk" } ;
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-ms-shortcut");
response.Content.Headers.ContentLength = stream.Length;
return response;
我上面评论的完整版本......
如果你在一个名为的方法中查看 chromium 源代码EnsureSafeExtension,我们看到代码:
if (IsShellIntegratedExtension(extension))
extension = kDefaultExtension; //<--"download"
where IsShellIntegratedExtension
返回 true 为lnk
扩展名:
if ((extension_lower == FILE_PATH_LITERAL("local")) ||
(extension_lower == FILE_PATH_LITERAL("lnk")))
return true;
代码中的注释说:
// Right-clicking on shortcuts can be magical.
因此,您看到的是预期的行为,因为 Chrome 开发人员认为潜伏在右键单击行为中的漏洞.lnk
files.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)