从电子邮件中的链接点击后,下面的代码会导致一个PDF文档在浏览器中打开:在Adobe Reader中打开PDF,而不是在浏览器
Response.ContentType = mime;
Response.WriteFile(path);
HttpContext.Current.ApplicationInstance.CompleteRequest();
有没有什么办法来强迫客户端在Adobe Acrobat/reader中本地打开它?
从电子邮件中的链接点击后,下面的代码会导致一个PDF文档在浏览器中打开:在Adobe Reader中打开PDF,而不是在浏览器
Response.ContentType = mime;
Response.WriteFile(path);
HttpContext.Current.ApplicationInstance.CompleteRequest();
有没有什么办法来强迫客户端在Adobe Acrobat/reader中本地打开它?
客户端的行为方式取决于多种因素,包括客户端的设置...你可以试试这个
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename="+filePath);
Response.WriteFile(path);
HttpContext.Current.ApplicationInstance.CompleteRequest();
是的,它做到了!那么,无论如何,在一些浏览器。其他人的工作方式完全相反! – CompanyDroneFromSector7G 2012-01-31 17:22:20
你能做的就是增加一个内容处置头的最好的事情。这应该会导致出现下载文件对话框。
Response.AddHeader("content-disposition", "attachment;filename=xxx.pdf");
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.pdf");
Response.TransmitFile(Server.MapPath("~/images/sailbig.pdf"));
Response.End();
这里的一些好的信息,以帮助:Downloading a File with a Save As Dialog in ASPNET和c# dynamically rename file upon download request和Handling file downloads using ASP.NET MVC如果你使用MVC
谢谢你有用的信息。 – CompanyDroneFromSector7G 2012-01-31 17:29:04
我相信,在浏览器中打开VS在Adobe Reader中打开一个浏览器/用户设定。你不可能通过C#来解决这个问题。 – 2012-01-31 16:25:16
HTTP规范允许您指定正在发送的二进制信息的***类型***,但无法指定特定的应用程序来处理内容。充其量,您可以强制用户下载PDF并手动打开该应用程序,该应用程序应在其原生PDF阅读器中打开,对于许多人来说,该阅读器是Adobe Acrobat/Reader。 – 2012-01-31 16:36:48