ASP.NET 4:Htt的presponse在新的浏览器打开? [英] ASP.NET 4: HttpResponse open in NEW Browser?

查看:688
本文介绍了ASP.NET 4:Htt的presponse在新的浏览器打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是PDF generater的utlizes的Htt presponse。有没有一种方法(或许通过一个头标记),打开一个新的窗口,而不是同一个PDF?我不希望用户被定向从网站而去...

这里的code我使用的是:

  System.Web.Htt presponse响应= System.Web.HttpContext.Current.Response; response.Clear();
response.AddHeader(内容类型,应用程序/ PDF格式);
response.AddHeader(内容处置,
    内联;文件名=+ downloadName +;大小=+ downloadBytes.Length.ToString());
response.Flush();
response.BinaryWrite(downloadBytes);
response.Flush();
到Response.End();


解决方案

如果您还没有产生自己的链接,您可以这样做,在服务器端。但如果你有,那么作为罗伯特说,提供与℃的目标;一个方式> 链接

有一个服务器端的替代方案,那就是设置内容类型为应用程序/ octect流,以便该文件是下载和用户将能够打开它与外界首选浏览器的应用程序。请参见这里以上。

您还需要使用内容处置头,可以提供的文件名,这样客户机可以知道什么文件类型是它的后,它已被下载二进制

 内容处置:附件;文件名= my.pdf;

I am using a PDF generater that utlizes HttpResponse. Is there a way (perhaps passing a header tag) to open the PDF in a NEW windows instead of the same one? I don't want the user to be directed away from the website...

Here's the code I'm using:

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;        response.Clear();
response.AddHeader("Content-Type", "application/pdf");
response.AddHeader("Content-Disposition",
    "inline; filename=" + downloadName + "; size=" + downloadBytes.Length.ToString());
response.Flush();
response.BinaryWrite(downloadBytes);
response.Flush();
response.End();

解决方案

You cannot do that on server side if you have not generated the link yourself. But if you have, then as Robert said, provide a target with the <a> link.

There is a server-side alternative and that is to set the content type to application/octect-stream so that the file is download and user will be able to open it with the application of choice outside browser. See here for more.

You also need to use content disposition header to provide the file name so that client can know what file type is it after it has been downloaded as binary.

Content-Disposition: attachment; filename=my.pdf;

这篇关于ASP.NET 4:Htt的presponse在新的浏览器打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆