2017-07-02 80 views
0

我尝试打开一个模式窗口 一个PDF我面对显示在一个模式窗口中的PDF下载不

<<div class="modal fade" id="basic" tabindex="-1" role="basic" aria- 
    hidden="true"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal" aria- 
        hidden="true"> 
       </button> 
      </div> 
      <div class="modal-body"> 
       <iframe id="Iframe1" src="" runat="server" width="540" height="600"></iframe> 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn red btn-outline" data- 
        dismiss="modal"> 
        أغلق</button> 
      </div> 
     </div> 
     <!-- /.modal-content --> 
    </div> 
</div> 

一个问题,我给的iframe一个src来显示PDF文件,

   frame1.Attributes.Add("src", "~/file.pdf"); 

问题是下载管理器强制要下载的文件,而不是出现在模式, 所以我尝试添加下面的代码,但它在所有的页面的开放不是模式

string x ="~/file.pdf"; 
       Response.ContentType = "Application/pdf"; 
       Response.WriteFile(HttpUtility.HtmlEncode(x)); 
       Response.End(); 
       frame1.Attributes.Add("src", x); 

回答

0

您可以做两件事,两件事都与标题中的content-disposition有关。 关键是返回PDF与content-dispositioninline

所以,你可以设置在IIS:

  • 转到文件
  • 属性
  • 集内容处置,内联; filename =“File1.pdf”

或者制作你自己的FileDownloader.aspx。并在其中设置内容部署:

Response.ContentType = "Application/pdf"; 
Response.setHeader("Content-disposition", "inline; filename=\"File1.pdf\""); 
Response.WriteFile(HttpUtility.HtmlEncode("file1.pdf")); 
Response.End(); 

,并在您的iFrame你只是针对下载

frame1.Attributes.Add("src", "FileDownloader.aspx");