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.
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.
SharePoint Web Application Asp.Net Impersonation statues in IIS has been enabled.
- 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.
- 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.
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.