I am attempting to generate a pdf from a SSRS report using URL Access in C#. (In the business layer behind a WebApi Controller) I create an instance of the HttpClient, assign correct credentials and form the request URL like:
http://sqlserver1/ReportServer/Pages/ReportViewer.aspx?/Clients/Acme/AcmeActivitySummary&rs:Command=Render&rs:format=pdf&Region=west&CutOffDate=10/25/2015
If I put my URL in a browser, it downloads the expected PDF file. When I execute this URL from the HttpClient instance to return a stream, I get a 401 Unauthorized Error.
If I open up Fiddler to see why...it works as expected.
How do I make this work without having to use Fiddler...and why doesn't it work now?
The HyperText Transfer Protocol (HTTP) 401 Unauthorized response status code indicates that the client request has not been completed because it lacks valid authentication credentials for the requested resource.
401 - Unauthorized: Access is denied due to invalid credentials. You do not have permission to view this directory or page using the credentials that you supplied.
Make sure that the URL is typed correctly. Verify the API documentation of the service you are trying to reach and make sure you have selected the right authorization type in Postman. Visit the service provider's page and look for a Sign in link. Enter your credentials and then try the page again.
Somewhere along the lines Microsoft changed the "standard" for URL Access to SSRS. The URL Pattern " http://{Server}/ReportServer/Pages/ReportViewer.aspx?/{Path to Report File} & [commands] & [parameters]
was deprecated in favor of
http://{server}/reportserver?/{path} & [commands] & [parameters].
HOWEVER...the old url pattern will still work 'sometimes'. SSRS will still receive the request at the old 'endpoint' and, if the request can be forwarded it will do so. So a 'normal' request from a browser (or from Fiddler) appears to work just fine. The problem is with the HttpClient request, which SSRS will not forward to the new endpoint...and it just returns the [somewhat confusing] 401 Unauthorized exception...which apparently means "I am not authorized to forward this request" not "you are not authorized to access this resource".
(after losing more time than I care to admit finding this...I thought a post here would be helpful to others.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With