The request failed with HTTP status 401: Unauthorized. Reporting Service ReportViewer in SharePoint Visual WebPart

In this article, I’m going to solve the below issue

The request failed with HTTP status 401: Unauthorized.


Scenario

When I tried to use a Reporting Service Report Viewer inside a SharePoint Visual WebPart that has been deployed successfully.

But unfortunately when I tried to browse the report I got the following error :

The request failed with HTTP status 401: Unauthorized.

The request failed with HTTP status 401: Unauthorized.

I investigated this issue by creating a new ASP.Net Web Site solution with the same code that I have used in Visual WebPart. It has been worked properly.

That means the issue is related to SharePoint Web Part and there is no problem in the code.


Cause

The SharePoint Web Application ASP.Net Impersonation statues in IIS has enabled that cause The request failed with HTTP status 401: Unauthorized.


Solution

  • Start > Administrative Tools > IIS Manager.
  • Navigate to the SharePoint web application >  Authentication > Select Asp.Net Impersonate > For Right side > below Actions > Click on Disable.
  • The ASP.Net Impersonation status is disabled.

Disable ASP.Net Impersonation in IIS

  • The Report viewer inside Visual WebPart should be working now.

Unfortunately. the previous solution effects on the “Search Craw”l as I mentioned before at Error HRESULT E_FAIL has been returned from a call to a COM component

Error HRESULT E_FAIL has been returned from a call to a COM component

The “Error HRESULT E_FAIL has been returned from a call to a COM component” error will be raised, If the ASP.Net Impersonation status is disabled.

So to solve “The request failed with HTTP status 401: Unauthorized” without affecting the “Search Crawl”, you should do the following:

  • Go back to Enable ASP.NET Impersonate, this is will lead to raising “The request failed with HTTP status 401: Unauthorized” again!
  • So the available workaround to avoid this error is disabling ASP.NET Impersonate in code.

Disable ASP.NET Impersonate using C#


//Define impersonationContext.
public System.Security.Principal.WindowsImpersonationContext impersonationContext;
//disable ASP.Net Impersonation.
impersonationContext = System.Security.Principal.WindowsIdentity.Impersonate(System.IntPtr.Zero);
//Insert your code that runs under the security context of the authenticating user here.
//Enable Impersonation.
impersonationContext.Undo();

Please, don’t hesitate to share with us any other workarounds in comments.


Applies To
  • SharePoint 2013.
Advertisements

6 thoughts on “The request failed with HTTP status 401: Unauthorized. Reporting Service ReportViewer in SharePoint Visual WebPart

  1. This isn’t a proper fix, in fact its more of a hack. Your having obvious issues with your authentication configuration on the server (are you using Kerberos? if so are all your spn’s setup correctly ) or potentially this is caused by incorrect formatting on the report URL. can you post your configuration of the report URL / location in the report viewer webpart.

    Like

  2. This isn’t a proper fix, in fact its more of a hack. Your having obvious issues with your authentication configuration on the server (are you using Kerberos? if so are all your spn’s setup correctly ) or potentially this is caused by incorrect formatting on the report URL. can you post your configuration of the report URL / location in the report viewer webpart. …

    Like

    1. This isn’t a proper fix, in fact its more of a hack. Your having obvious issues with your authentication configuration on the server (are you using Kerberos? if so are all your spn’s setup correctly ) or potentially this is caused by incorrect formatting on the report URL. can you post your configuration of the report URL / location in the report viewer webpart. …

      Like

  3. Hi , this error cause of security validation for other tiers in sharepoint, you need to stop page security validation , or add security digest control in the master page .

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s