I tried to use Reporting service Report Viewer that connect to Report Server remottly in custom web part in SharePoint.
I tried to create test ASP.Net Web Site solution with the same code and my surprise it’s worked successfully but in web part not worked :(
I decided to check Authentication of SharePoint Site Start–> Administrative Tools –> IIS Manager then navigate to my SharePoint site then select Authentication .
At ASP.Net Impersonate it’s Enabled
When I set Asp.Net Impersonate to false it’s worked successfully :)
Unfortunately Over two hour I tried to use Search but not worked i try to run full crawl search from central administration but also not worked :(
I decided to check Crawl Log and found the following error
error hresult fail has been returned from a call to a com component
I ask my self what’s the changes i do and went back to Enable Asp.Net Impersonate , and tried to run Full Crawl search and the error disappeared and search Work Successfully
but the main error back again :)
The request failed with HTTP status 401: Unauthorized.
I decided to disable Asp.Net Impersonate at the moment that I show my report So i will disable it via the following code in my web part
public System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext = System.Security.Principal.WindowsIdentity.Impersonate(System.IntPtr.Zero);
//Insert your code that runs under the security context of the authenticating user here.
Good Luck :)