I have a report saved on SQL2005 report server and I want to return the PDF rendering of this report. I understood this when working with the local * .rdlc file ( and I wrote about it ), but not when *. rdl is on the report server. I get error 401 Not Authorized in line ...
reportViewer.ServerReport.SetParameters(reportDefinition.ReportParameters);
The report rendering method is used here.
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;
Another thing you are missing is the WindowsImpersonationCredentials class.
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); } }
Other things you might need ...
- This works on the intranet and impersonation is enabled.
- Logging indicates that the impersonation user is configured correctly.
- This one works when working in Visual Studio (
http://localhost:devport ), and it works when working in my development area ( http://localhost/myApplication ). It does not work when working on our test or production servers. - I tried solutions both with system.net.defaultProxy settings and without them in web.config. None worked.
What am I doing wrong? Is this a server setup? Is this a code? Is this web.config?
Jarrett meyer
source share