Ho un report salvato su un server di report SQL2005 e voglio restituire un PDF renderizzato di questo report. Ho capito questo quando si lavora con un file * .rdlc locale (and I've blogged about it), ma non quando il * .rdl risiede su un server di report. Sto ottenendo un 401 non autorizzato errore alla linea di ...Visualizzatore report SSRS + credenziali ASP.NET 401 Eccezione
reportViewer.ServerReport.SetParameters(reportDefinition.ReportParameters);
Ecco il metodo utilizzato per il rendering del report.
public byte[] Render(IReportDefinition reportDefinition)
{
var reportViewer = new ReportViewer();
byte[] renderedReport;
try
{
var credentials = new WindowsImpersonationCredentials();
reportViewer.ServerReport.ReportServerUrl = new Uri("http://myssrsbox", UrlKind.Absolute);
reportViewer.ServerReport.ReportServerCredentials = credentials;
reportViewer.ServerReport.ReportPath = reportDefinition.Path;
// Exception is thrown on the following line...
reportViewer.ServerReport.SetParameters(reportDefinition.ReportParameters);
string mimeType;
string encoding;
string filenameExtension;
string[] streams;
Warning[] warnings;
renderedReport = reportViewer.ServerReport.Render(reportDefinition.OutputType, reportDefinition.DeviceInfo, out mimeType, out encoding, out filenameExtension, out streams, out warnings);
}
catch (Exception ex)
{
// log the error...
throw;
}
finally
{
reportViewer.Dispose();
}
return renderedReport;
}
L'altra cosa che ti manca è la classe WindowsImpersonationCredentials.
public class WindowsImpersonationCredentials : IReportServerCredentials
{
public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
{
authCookie = null;
userName = password = authority = null;
return false;
}
public WindowsIdentity ImpersonationUser
{
get { return WindowsIdentity.GetCurrent(); }
}
public ICredentials NetworkCredentials
{
get { return null; }
}
public override string ToString()
{
return String.Format("WindowsIdentity: {0} ({1})", this.ImpersonationUser.Name, this.ImpersonationUser.User.Value);
}
}
Altre cose potrebbe essere necessario sapere ...
- Questo è in esecuzione su una rete Intranet, e rappresentazione è attivata.
- La registrazione indica che l'utente di rappresentazione è stato impostato correttamente.
- Questo funziona durante l'esecuzione in Visual Studio (
http://localhost:devport
), ed è funziona quando si esegue sulla mia casella di sviluppo (http://localhost/myApplication
). È non funziona quando è in esecuzione sui nostri server di test o di produzione. - Ho provato soluzioni con e senza impostazioni system.net.defaultProxy in web.config. Nessuno dei due ha funzionato.
Cosa sto sbagliando? È un'impostazione del server? È un codice? È web.config?
fa l'utente rappresentazione hanno accesso al server di report - che la relazione in particolare? – NYSystemsAnalyst
Hai provato a eseguire IIS con l'utente di rappresentazione sulla tua macchina di sviluppo (localhost) per emulare più da vicino ciò che sta accadendo sul tuo server di prova? Sembra un problema di autorizzazioni flat out con il tuo utente di rappresentazione rispetto al server di report o al database del server di report. Presumo che l'utente di rappresentazione sia un account di dominio. –
@NYSystemsAnalyst - Sì, l'utente di rappresentazione ha accesso alla directory appropriata sul server di report. –