In this article, I’m going to solve “The request failed with HTTP status 401 Unauthorized” that you may face when using the Reporting Service Report Viewer in the SharePoint Visual Web Part.
When I tried to use a Reporting Service Report Viewer inside a SharePoint Visual Web Part that has been deployed successfully. But when I tried to browse the report I got the following error:
The request failed with HTTP status 401: Unauthorized.
I have investigated this issue by creating a new ASP.Net Web Site solution with the same code that I have used in Visual WebPart that has been worked properly. That means the issue is related to SharePoint Web Part and there is no problem in the code.
This issue “The request failed with HTTP status 401 Unauthorized” occurs if the SharePoint Web Application ASP.Net Impersonation status has been enabled in IIS.
- 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.
- The Report viewer inside Visual Web Part should be working now.
Unfortunately. the previous solution effects on the “Search Crawl” as I mentioned before at 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.
Disable ASP.NET Impersonate using C#
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.
//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.
- SharePoint 2013.
- SharePoint 2010.