0

我確信我的問題標題沒有太大意義,但現在我想不起來了。將身份驗證標頭傳遞給iframe中的圖片請求

問題:我的主要任務是在ASP.NET MVC應用程序的一個頁面內的彈出窗口中顯示SSRS報告的所有頁面

要做到這一點我用下面的方法:

  1. 添加在MyPage.cshtml一個jQuery彈出(我需要這個報告裏面彈出內容)
  2. 在這個彈出打開(在某些客戶端動作),我做一個jquery ajax請求到第二頁proxyPage.aspx
  3. 在代理頁面我做的WebRequest與網絡憑證的reportserver並得到報告HTML

    WebRequest request = WebRequest.Create("http://MyReportServer/ReportServer?/ MyReportName&rs:Command=Render&rs:Format =HTML4.0&rc:Toolbar=false&Param1=blabla123"); 
        request.Credentials = new NetworkCredential(MYUSERNAME, MYPASSWORD); 
        HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
        Stream receiveStream = response.GetResponseStream(); 
        StreamReader readStream = new StreamReader(receiveStream, System.Text.Encoding.UTF8); 
        string str = readStream.ReadToEnd(); 
        Response.Write(str); 
    
  4. 來自proxyPage的HTML我在彈出窗口中使用div編寫代碼或使用iframe在其中顯示完整代理頁面。

  5. 到這裏一切順利的話,然後我得到了另一個問題爲此我寫了這個問題

  6. 當報告的HTML,在彈出的獲取呈現它使請求報告服務器去取回嵌入在報告中的圖像。

因爲這些請求報告服務器不像我在步驟3中那樣發送網絡憑證,所以我得到提示輸入憑證。

我需要一種方法,通過這種方法,這些圖像請求可能以某種方式通過我之前提供的憑據進行驗證。

回答

0

SSRS將在您指定的位置流式傳輸資源。

private byte[] InternalRenderReport(Report report, List<ReportParameter> parameters, string format, int pageNumber, ref int totalPages, string virtualTempFolder, string physicalTempFolder) 
     { 
      CheckConnection(); 
      byte[] result = null; 
      ReportExecution2005.ReportExecutionService _execService=new ReportExecution2005.ReportExecutionService(); 


      sys = _systemService.GetCurrentSystem(); 
      _execService.Url = sys.ReportingServices.ServiceRootURL+"/ReportExecution2005.asmx"; 
      NetworkCredential credentials = new NetworkCredential(sys.ReportingServices.Credentials.UserName, 
                   sys.ReportingServices.Credentials.Password, 
                   sys.ReportingServices.Credentials.Domain); 
      _execService.Credentials=credentials; 

      ReportExecution2005.ParameterValue[] rsParams = null; 
      if (parameters != null) 
      { 
       rsParams = new ReportExecution2005.ParameterValue[parameters.Count]; 
       int x = 0; 
       foreach (ReportParameter p in parameters) 
       { 
        rsParams[x] = new ReportExecution2005.ParameterValue(); 
        rsParams[x].Name = p.ParameterName; 
        rsParams[x].Value = p.SelectedValue; 
        x++; 
       } 
      } 
      StringBuilder devInfo = new StringBuilder(); 
      if (format.ToUpper().StartsWith("HTML")) 
      { 
       devInfo.Append("<DeviceInfo>"); 
       devInfo.Append("<HTMLFragment>True</HTMLFragment>"); 
       devInfo.Append("<Section>" + pageNumber.ToString() +"</Section>"); 
       devInfo.Append("<StreamRoot>" + virtualTempFolder + "</StreamRoot>"); 
       /*devInfo.Append("<Zoom>200</Zoom>");*/ 
       devInfo.Append("</DeviceInfo>");     
      } 
      else 
       devInfo.Append("<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"); 

      string extension; 
      string mimeType; 
      string encoding; 
      string[] streamIDs = null; 
      ReportExecution2005.Warning[] warnings = null; 




      ReportExecution2005.ExecutionHeader execHeader = new ReportExecution2005.ExecutionHeader(); 
      ReportExecution2005.ExecutionInfo rpt = _execService.LoadReport(report.ReportPath, null); 

      if(rsParams!=null) 
       _execService.SetExecutionParameters(rsParams, "en-us"); 
      _execService.ExecutionHeaderValue = execHeader; 
      _execService.ExecutionHeaderValue.ExecutionID = rpt.ExecutionID; 


      //result = _execService.Render2(format, devInfo, ReportExecution2005.PageCountMode.Actual, out extension, out mimeType, out encoding, out warnings, streamIDs); 
      result = _execService.Render(format, devInfo.ToString(), out extension, out mimeType, out encoding, out warnings, out streamIDs); 

      if (format.ToUpper().StartsWith("HTML")) 
      { 


       // For each image stream returned by the call to render, 
       // render the stream and save it to the application root 
       string FilePath = physicalTempFolder; 
       byte[] image; 
       // For each image stream returned by the call to render, 
       // render the stream and save it to the application root 
       foreach (string streamID in streamIDs) 
       { 
        image = _execService.RenderStream("HTML4.0", streamID, null, out encoding, out mimeType); 

        FileStream stream = File.OpenWrite(FilePath + streamID); 
        stream.Write(image, 0, image.Length);      
        stream.Close(); 
       } 
      } 

      rpt = _execService.GetExecutionInfo(); 
      totalPages = rpt.NumPages; 

      return result; 
     } 

這將返回原始HTML或內容推送文件。我向要部署到服務器的解決方案添加了Temp文件夾。你可以放置在臨時文件夾中的web.config文件包含以下內容,以便擴展更少內容SSRS將使用流時呈現:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
    <staticContent> 

     <mimeMap fileExtension=".*" mimeType="image/png" /> 


    </staticContent> 
    <handlers> 
     <clear /> 

     <add name="StaticFile" path="*" verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Read" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" /> 
    </handlers> 
    </system.webServer> 
</configuration> 

然後使用下面的方法函數來獲得物理和虛擬臨時文件夾:

PhyscicalTempFolder= AppDomain.CurrentDomain.BaseDirectory + @"Temp\"; 
VirtualTempFolder=return Url.Content("~/Temp/"); 

最後清理每一天後,您可以添加類似一個PowerShell命令:

Remove-Item D:\xxx\WebApplications\ExternalReports\Temp\* -exclude *.config 

然後添加調用PS SC名爲.bat RIPT:

powershell -command "& 'C:\xxx\Scripts\SSRSCleanTempFiles\SSRSCleanTempFiles.ps1'" 

有了這個,你可以在服務器上配置計劃任務的日常.bat文件調用,並清潔你的應用程序的temp文件夾。

相關問題