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

When I was trying to use a Reporting Service Report Viewer inside a SharePoint Visual WebPart that had been deployed successfully but unfortunately when I tried to show the report I got the following error :

The request failed with HTTP status 401: Unauthorized.

error1

I investigated this issue by creating a new ASP.Net Web Site solution with the same code that used before in Visual WebPart where it has been worked properly.So that the issue is related to SharePoint Web Part and no problem with code.

Cause :

SharePoint Web Application Asp.Net Impersonation statues in IIS has been enabled.

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.
  • Now Asp.Net Impersonation statues should be Disabled.

iis imporsenate

  • Now The Report viewer inside Visual WebPart should be worked properly.

Unfortunately the previous solution will effect on Search Crawl as I mentioned before in this article

searchcrawl error

This search error is raised , If the Asp.Net Impersonation statues was Disabled and to overcome this issue I should follow the mentioned steps below :

  • Go back to Enable Asp.Net Impersonate that will raise  The request failed with HTTP status 401: Unauthorized again.thence,
    • At the moment that I need to show the report inside Visual WebPart I will disable Asp.Net Impersonate by using  the following code.
//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();

It’s a workaround for this issue but if you have a better solution than this. please, don’t hesitate to provide us with it in comments.

Enjoy :)

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

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s