gpt4 book ai didi

google-chrome - Chrome 和 Firefox 中的 MVC 5 内容处置错误

转载 作者:行者123 更新时间:2023-12-02 01:02:04 25 4
gpt4 key购买 nike

我想在浏览器中以pdf格式显示系统的用户手册。

以下代码在 IE9 中可以正常工作,但不能

Chrome - 从服务器收到错误重复错误

Firefox - 损坏的内容错误

MVC 5 代码(我认为是在添加 IE 可以处理的重复 header )

只是想知道有什么方法可以在所有浏览器上使用吗?

public FileResult UserManual()
{
var FileName = "user-manual.pdf";
var cd = new ContentDisposition
{
Inline = true,
FileName = FileName
};
Response.AddHeader("Content-Disposition", cd.ToString());
string path = AppDomain.CurrentDomain.BaseDirectory + "App_Data/";
return File(path + FileName, MediaTypeNames.Application.Pdf, FileName);

}

最佳答案

我知道这已经过时了,但我今天遇到了同样的问题。

如果添加“Content-Disposition” header ,则不要返回添加了“FileName”参数的文件

检查这个:

if (myFile.IsInlineContent()) // Evaluate the content type to check if the file can be shown in the browser
{
Response.AppendHeader("content-disposition", $"inline; myFile.Filename}");
return File(myFile.Path, myFile.Type); // return without filename argument
}
// if not, treat it as a regular download
return File(myFile.Path, myFile.Type, myFile.Filename); // return with filename argument

希望这有助于...

关于google-chrome - Chrome 和 Firefox 中的 MVC 5 内容处置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27426709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com