2009-07-24 4 views
1

Ich versuche, einen Bericht als pdf in asp.net c# auszuführen. Ich habe alles super funktioniert, bis auf die sqlauth cookie. Wenn ich einen iframe benutze und einen Dummy-Bericht rendere, dann benutze diesen sqlAuthCookie Cookie (gesetzt vom Berichtsserver) im Code-Behind, es funktioniert, also weiß ich, dass meine Syntax und Methode usw. korrekt ist. Was ich tun muss, ist das Hinzufügen des sqlauth cookie zum CookieContainer von ReportExecution Service oder eine andere Methode zum Übergeben von Anmeldeinformationen. Ich verwende Forms Authentication. Ich verwende einen ashx Handler mit einem jquery ajax Aufruf, um den Bericht auszuführen. Hier ist mein Code hinter der Seite.Set sqlAuthCookie für SSRS Execution Service

public void ProcessRequest(HttpContext context) 
    { 
     // 8863443a-06d6-4aeb-8fa8-43be545da1a3 
     var rs = new ReportExecutionService(); 
     rs.Credentials = CredentialCache.DefaultCredentials; 
     //rs.Credentials = new NetworkCredential("zachariah.curtis", "password", "AGLO"); 
     rs.Url = ConfigurationManager.AppSettings["ReportExecutionURL"]; 

     NetworkCredential creds = rs.Credentials.GetCredential(context.Request.Url, context.User.Identity.AuthenticationType); 
     rs.LogonUser(creds.UserName, creds.Password, null); 

     var cookies = context.Request.Cookies.AllKeys.ToList(); 
     var cookies3 = rs.CookieContainer.GetCookies(new Uri(rs.Url)); 
     var sqlauth = context.Request.Cookies["sqlAuthCookie"]; 
     rs.CookieContainer = new CookieContainer(); 
     cookies.ForEach(delegate(String item) 
     { 
      rs.CookieContainer.Add(new Cookie(context.Request.Cookies[item].Name, context.Request.Cookies[item].Value, context.Request.Cookies[item].Path, context.Request.Cookies[item].Domain ?? ".usda.gov")); 
      rs.CookieContainer.Add(new Cookie("sqlAuthCookie", "A78B8A2D714BF058DF7258927717A4D34FA9F8A0BA54FCCB006543DEBF755D2670636E172675107A9FCAF77F66A0E7E2EE4321464602C7E61138C224B8612B05E12DC1DFF878E8748CE267FF19839198", "/", "iasdev.dev.sc.egov.usda.gov")); 
     }); 


     // Render arguments 
     byte[] result = null; 
     // Make sure you use your correct org database name of the following line 
     string reportPath = "/ProTractsCMT/TestReport"; 
     var contractId = context.Request["ContractId"]; 
     string format = "PDF"; 
     string historyID = null; 
     string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; 

     // Prepare report parameter. 

     ParameterValue[] parameters = new ParameterValue[1]; 
     parameters[0] = new ParameterValue(); 
     parameters[0].Name = "@CONTRACTID"; 
     parameters[0].Value = contractId; 

     DataSourceCredentials[] credentials = null; 
     string showHideToggle = null; 
     string encoding; 
     string mimeType; 
     string extension; 
     Warning[] warnings = null; 
     ParameterValue[] reportHistoryParameters = null; 
     string[] streamIDs = null; 

     ExecutionInfo execInfo = new ExecutionInfo(); 
     ExecutionHeader execHeader = new ExecutionHeader(); 

     rs.ExecutionHeaderValue = execHeader; 

     execInfo = rs.LoadReport(reportPath, historyID); 

     //rs.SetExecutionParameters(parameters, "en-us"); 
     string SessionId = rs.ExecutionHeaderValue.ExecutionID; 


     Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID); 

     try 
     { 
      result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs); 
      execInfo = rs.GetExecutionInfo(); 
      Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime); 
     } 

     catch (SoapException err) 
     { 
      Console.WriteLine(err.Detail.OuterXml); 
     } 
     context.Response.ContentType = "text/plain"; 
     // save rendered pdf to db 
     if (new calculations().SaveReport(result)) 
     { 
      context.Response.Write("true"); 

     } 
     else 
     { 
      context.Response.Write("true"); 

     } 
    } 

Sie können sehen, wo die rs.CookieContainer.Add(new Cookie("sqlAuthCookie" ist, und das ist, wie ich es funktioniert. Bitte bitte bitte Hilfe !!! Danke allen!

Antwort

0

Erfordert Ihr Entwurf, dass Sie die Anmeldeinformationen/Authentifizierungsdaten des aktuell angemeldeten Benutzers an SSRS übergeben? Würde dieser Benutzer also Berichte mit diesen bestimmten Anmeldeinformationen direkt ausführen können?

Üblicherweise würde ich eher davon aus, dass Sie Ihre RS-Ausführungs-Engine mit vordefinierten Benutzer in der Art und Weise zuzugreifen, und führen Sie es offenbar bereits versucht:

//rs.Credentials = new NetworkCredential("zachariah.curtis", "password", "AGLO"); 

Sie können diese Anmeldeinformationen in der App-Einstellungen konfigurieren.