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.
Cause
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.
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.
- 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.
Applies To
- SharePoint 2013.
- SharePoint 2010.
If some one wants expert view concerning blogging and site-building
afterward i suggest him/her to go to see this weblog, Keep
up the fastidious work.
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 .
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. …
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. …
No i am not using Kerberos and this method worked successfully with me 🙂 any way thanks for your comment and i welcome with any solution from you
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.