C# 在新窗口中打开jpg/pdf

C# 在新窗口中打开jpg/pdf,c#,asp.net,response.transmitfile,C#,Asp.net,Response.transmitfile,当我尝试使用下面的代码在新窗口中打开文件时,它正在下载文档,而不是在新窗口中打开。当我打开下载的文档时,它看起来不错 但我希望文档在新窗口中打开。谢谢你的帮助 WebForm2Test.aspx 内容处置标头导致浏览器保存文件,而不是内联显示文件。您仍然需要内容类型标头,但请在删除内容处置后重试 如果此标头用于具有application/octet-stream内容类型的响应,则暗示用户代理不应显示响应,而应直接进入“将响应另存为…”对话框 随着时间的推移,这已演变为内容。如果发送内容处置,则应

当我尝试使用下面的代码在新窗口中打开文件时,它正在下载文档,而不是在新窗口中打开。当我打开下载的文档时,它看起来不错

但我希望文档在新窗口中打开。谢谢你的帮助

WebForm2Test.aspx
内容处置标头导致浏览器保存文件,而不是内联显示文件。您仍然需要内容类型标头,但请在删除内容处置后重试

如果此标头用于具有application/octet-stream内容类型的响应,则暗示用户代理不应显示响应,而应直接进入“将响应另存为…”对话框


随着时间的推移,这已演变为内容。如果发送内容处置,则应直接保存内容。根据我的经验,大多数浏览器似乎都是这样的。

要打开新的浏览器窗口吗?还是Windows预览?或者只是网页中的一个重叠对话框?我试图在新浏览器窗口或新浏览器选项卡中打开。insta提供的解决方案解决了这个问题。谢谢insta。这就解决了问题。由于我是一个新用户,我无法投票支持。我接受了答案。谢谢你提供的信息。
<a href="WebForm1Test.aspx" onclick="window.open('WebForm1Test.aspx','_blank')">WebForm1Test.aspx  </a>
public partial class WebForm1Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Writes Document
        System.IO.MemoryStream outStream = new System.IO.MemoryStream(Some_Base64_String);
        HttpContext.Current.Response.Expires = 0;
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.ClearContent();
        string STR_File_Name = "test"
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + test);

        //Known Content Types            
        if (OBJ_Document.CH_Document_Extension.ToUpper() == "JPG")
        {
            HttpContext.Current.Response.AppendHeader("Content-Type", "image/jpeg");
        }
        if (OBJ_Document.CH_Document_Extension.ToUpper() == "JPEG")
        {
            HttpContext.Current.Response.AppendHeader("Content-Type", "image/jpeg");
        }

        if (OBJ_Document.CH_Document_Extension.ToUpper() == "PDF")
        {
               HttpContext.Current.Response.AppendHeader("Content-Type", "application/pdf");
        }            

        using (FileStream file = new FileStream("c:\\file.bin", FileMode.Create, System.IO.FileAccess.Write))
        {
            byte[] bytes = new byte[outStream.Length];
            outStream.Read(bytes, 0, (int)outStream.Length);
            file.Write(bytes, 0, bytes.Length);
            outStream.Close();
        }

        HttpContext.Current.Response.TransmitFile("c:\\file.bin");
        outStream.Close();
        HttpContext.Current.Response.End();
    }
}