2009-03-22 3 views
18

Sono piuttosto nuovo in C# e il mio inglese non è così buono - mi dispiace in anticipo se mi manca un punto.Passing Credentials a Sql Report Server 2008

Ho provato a creare un sito Web ASP.NET con un controllo ReportService. Come forse già saprai, SSRS 2008 non consente il login anonimo. Così, ho provato a passare le credenziali a SSRS che saranno archiviate nella mia pagina web in modo che gli utenti possano vedere il rapporto senza effettuare il login.

Ho trovato il codice qui sotto e lo metto sul mio WebForm, ma io ' m avendo un problema con i parametri del report.

  • Se ci sono valori di default per i parametri del report, il codice qui sotto funziona bene.

  • Ma, se provo a cambiare il valore di un parametro, l'intera pagina è
    rinfrescati e prima di fare clic sul pulsante "Visualizza rapporto", tutti
    parametri sono riportati ai valori di default nulli o.

Qualsiasi suggerimento su come evitare aggiornare la pagina intera, o in un altro modo per passare l'informazioni di login per SSRS? Grazie mille in anticipo.

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

Sei sicuro che hanno interrotto l'autenticazione anonima da SSRS 2008? Potresti aver bisogno di configurarlo in IIS? – RobS

+0

Da: http://blogs.msdn.com/jameswu/archive/2008/07/15/anonymous-access-in-sql-rs-2008.aspx Quindi quello che è successo alla buona vecchia autenticazione anonima è RS 2005? La risposta breve è che non è più supportato. – adopilot

risposta

16

Io davvero non ho pasticciato con SSRS - ma il cappello ASP.NET mi dice si consiglia di avvolgere quella roba in un blocco if (!IsPostBack) per evitare che in esecuzione sul refresh della pagina. La mia ipotesi è che ReportViewer1.ServerReport.Refresh() recupera nuovamente i valori predefiniti.

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

Provo a tagliare la riga ReportViewer1.ServerReport.Aggiorna() ma sfortunatamente la stessa cosa è accaduta di nuovo. – adopilot

+0

Lo hai avvolto in un controllo IsPostBack? –

+3

ReportViewer1.ServerReport.ReportServerCredentials non ha setter – dcarneiro

0

Ho creato una nuova funzione e l'ho rilevata nella vista di progetto su proprietà, eventi, reportViewer. (Nella selezione INIT i)

Successivamente, la pagina funziona normalmente e posso modificare i valori per i parametri.

Default.aspx ora assomiglia:

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

E Default.aspx.cs assomiglia a questo

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

è possibile utilizzare il seguente codice nell'evento di caricamento della pagina per dare parametri

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(); 

Spero che questo funzioni per voi

0

ho trovato la soluzione per questo. devi prima impostare le credenziali, quindi devi impostare i parametri per 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();