Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

401 Unauthorized Error On SSRS URL Access ... but it works in Fiddler?

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?

like image 633
Cos Callis Avatar asked Feb 15 '16 18:02

Cos Callis


People also ask

What does the HTTP status code 401 indicate unauthorized?

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.

What does 401 unauthorized access is denied due to invalid credentials mean?

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.

How do I fix a 401 error in my postman?

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.


1 Answers

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.)

like image 61
Cos Callis Avatar answered Oct 20 '22 07:10

Cos Callis