2009-03-22 9 views
18

Jestem całkiem nowy w języku C#, a mój angielski nie jest zbyt dobry - przepraszam z góry, jeśli pominę punkt.Przekazywanie poświadczeń do serwera raportów Sql 2008

Próbowałem zbudować stronę internetową ASP.NET z kontrolką ReportService. Jak już wiesz, system SSRS 2008 nie zezwala na anonimowe logowanie. Próbowałem więc przekazać referencje do SSRS, które będą przechowywane na mojej stronie internetowej, dzięki czemu użytkownicy będą mogli zobaczyć raport bez logowania się.

Znalazłem poniższy kod i umieściłem go na moim WebForm, ale " m ma problem z parametrami raportu.

  • Jeśli są domyślne wartości dla parametrów raportu, poniższy kod działa w porządku.

  • Ale gdy próbuję zmienić wartość parametru, cała strona jest
    odświeżony i zanim kliknę przycisk „View Report”, wszystkie
    parametry są zresetowane do wartości domyślnych lub wartości null.

Wszelkie sugestie, jak uniknąć odświeżania całej strony lub inny sposób przekazania informacji logowania do SSRS? Z góry dziękuję.

using System; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
using System.Net; 
using Microsoft.Reporting.WebForms; 

public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     ReportViewer1.Width = 800; 
     ReportViewer1.Height = 600; 
     ReportViewer1.ProcessingMode = ProcessingMode.Remote; 
     IReportServerCredentials irsc =new CustomReportCredentials("administrator", "MYpassworw", "domena"); 
     ReportViewer1.ServerReport.ReportServerCredentials = irsc; 
     ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.0.1/ReportServer/"); 
     ReportViewer1.ServerReport.ReportPath = "/autonarudzba/listanarudzbi"; 
     ReportViewer1.ServerReport.Refresh(); 
    } 
} 

public class CustomReportCredentials : IReportServerCredentials 
{ 
    private string _UserName; 
    private string _PassWord; 
    private string _DomainName; 

    public CustomReportCredentials(string UserName, string PassWord, string DomainName) 
    { 
     _UserName = UserName; 
     _PassWord = PassWord; 
     _DomainName = DomainName; 
    } 

    public System.Security.Principal.WindowsIdentity ImpersonationUser 
    { 
     get { return null; } 
    } 

    public ICredentials NetworkCredentials 
    { 
     get { return new NetworkCredential(_UserName, _PassWord, _DomainName); } 
    } 

    public bool GetFormsCredentials(out Cookie authCookie, out string user, 
     out string password, out string authority) 
    { 
     authCookie = null; 
     user = password = authority = null; 
     return false; 
    } 
} 
+0

Czy jesteś pewien, że usunęli anonimowy auth z SSRS 2008? Może po prostu trzeba go skonfigurować w IIS? – RobS

+0

Od: http://blogs.msdn.com/jameswu/archive/2008/07/15/anonymous-access-in-sql-rs-2008.aspx Tak więc, co się stało z dobrym starym anonimowym uwierzytelnieniem jest RS 2005? Krótka odpowiedź brzmi, że nie jest już obsługiwana. – adopilot

Odpowiedz

16

ja naprawdę nie grzebał SSRS - ale mój ASP.NET kapelusz mówi mi, może chcesz zawinąć te rzeczy w bloku if (!IsPostBack) aby utrzymać go z jazdy na odświeżeniu strony. Domyślam się, że ReportViewer1.ServerReport.Refresh() ponownie pobiera wartości domyślne.

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!this.IsPostBack) 
    { 
     ReportViewer1.Width = 800; 
     ReportViewer1.Height = 600; 
     ReportViewer1.ProcessingMode = ProcessingMode.Remote; 
     IReportServerCredentials irsc =new CustomReportCredentials("administrator", "MYpassworw", "domena"); 
     ReportViewer1.ServerReport.ReportServerCredentials = irsc; 
     ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.0.1/ReportServer/"); 
     ReportViewer1.ServerReport.ReportPath = "/autonarudzba/listanarudzbi"; 
     ReportViewer1.ServerReport.Refresh(); 
    } 
} 
+0

Próbuję wyciąć wiersz ReportViewer1.ServerReport.Refresh(), ale niestety to samo stało się ponownie. – adopilot

+0

Czy zawinąłeś to w sprawdzanie IsPostBack? –

+3

ReportViewer1.ServerReport.ReportServerCredentials nie ma ustawiacza – dcarneiro

0

Zrobiłem nową funkcję i podniosłem ją w widoku projektu na właściwości, zdarzenia, reportViewer. (W wyborze INIT i)

Następnie strona działa normalnie i mogę zmienić wartości parametrów.

Defalult.aspx teraz wygląda:

</head> 
     <body> 
     <form id="form1" runat="server"> 
     <div> 
      <rsweb:ReportViewer ID="ReportViewer1" runat="server" onload="Admir"> 
      </rsweb:ReportViewer> 
     </div> 
     </form> 
    </body> 

I Default.aspx.cs wygląda to

public void Admir(object sender, EventArgs e) 
    { 
     ReportViewer1.Width = 800; 
     ReportViewer1.Height = 600; 
     ReportViewer1.ProcessingMode = ProcessingMode.Remote; 
     IReportServerCredentials irsc = new CustomReportCredentials("administrator", "mypass", "domena"); 
     ReportViewer1.ServerReport.ReportServerCredentials = irsc; 
     ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.0.1/ReportServer/"); 
     ReportViewer1.ServerReport.ReportPath = "/autonarudzba/listanarudzbi"; 
     ReportViewer1.ServerReport.Refresh(); 

    } 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
0

można wykorzystać następujący kod w przypadku obciążenia strona dać Parametry:

ReportParameter[] reportParameterCollection = new ReportParameter[1]; //Array size describes the number of paramaters. 
reportParameterCollection[0] = new ReportParameter(); 
reportParameterCollection[0].Name = "ACCMGR"; //Give Your Parameter Name 
reportParameterCollection[0].Values.Add("12"); //Pass Parametrs's value here. 
ReportViewer1.ServerReport.SetParameters(reportParameterCollection); 
ReportViewer1.ServerReport.Refresh(); 

Mam nadzieję, że to ci pomoże

0

znalazłem rozwiązanie dla tego. Najpierw należy ustawić poświadczenia, a następnie ustawić parametr reportviewer.

rvCommon.ProcessingMode = ProcessingMode.Remote; 
     rvCommon.ServerReport.ReportServerUrl = new System.Uri("SSRSReportServerURL"); 
     rvCommon.ServerReport.ReportPath = "/Report Parts/CustomerMainReport2" ; 

     Microsoft.Reporting.WebForms.ReportParameter[] RptParameters = new Microsoft.Reporting.WebForms.ReportParameter[1]; 
     rvCommon.ServerReport.ReportServerCredentials = new ReportCredentials("username", "password", ""); 

     RptParameters[0] = new Microsoft.Reporting.WebForms.ReportParameter("CustomerId", "1"); 
     rvCommon.ServerReport.SetParameters(RptParameters); 
     rvCommon.ServerReport.Refresh();