none
LocalReport.Render function, changes ImpersonationLevel to None in ReportViewer 10.0 (in 9.0 it does not) - why, how to solve this? RRS feed

  • Question

  • We have a ASP.NET application targeting .net 3.5. We recently switched to VS 2010 and we had to change references to ReportViewer from 9.0 to 10.0. To our surprise it turned out that LocalReport.Render function in ReportViewer 10.0 is changing ImpersonationLevel from "Impersonation" to "None". Please correct me if I am wrong but this has to be a bug - it can not be a feature!

    Let me show You how to reproduce a problem:

    1) Create Your own WebApplication. Add an .rdlc file to it.

    2) In web.config add <identity impersonate="true"/>

    3) Try printing .rdlc file an check impersonation level before and after printing, with ReportViewer 9.0 and 10.0, like that:

    System.Security.Principal.WindowsIdentity widnowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
    
          //Render the report
          byte[] renderedBytes = localReport.Render(
            reportType,
            deviceInfo,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);
    
          widnowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();

    4) What You will see is that: With ReportViewer 9.0 referneced, You will see that "windowsIdentity.ImpersonationLevel" parameter before and after printing stays the same and equals "Impersonation". But with ReportViewer 10.0 referenced, You will see that parameter "windowsIdentity.ImpersonationLevel" before printing equals "Impersonation" and after printing it equals "None".

    WHY? And how to go around this problem - other than impersonating user again (in the code) after every call to LocalReport.Render???

    Thursday, August 19, 2010 3:45 PM

All replies

  • Any ideas?
    • Proposed as answer by NZCoder Thursday, September 9, 2010 4:29 AM
    Friday, August 20, 2010 12:20 PM
  • I had the same problem - what I do is revert to the ASP.NET Account user for the duration of the report rendering code (not just the call to 'Render') as shown below:

    Snippet

    using
     (WindowsImpersonationContext
     context = WindowsIdentity
    .Impersonate(IntPtr
    .Zero))
    {
        // LocalReport code, including 'Render' goes here...
    }

    • Proposed as answer by NZCoder Thursday, September 9, 2010 4:37 AM
    Thursday, September 9, 2010 4:36 AM
  • Your proposal seems fine. But there is one more thing You should notice. Report Viewer does not only change Impersonation level. It also changes Globalization info. We have culture set to "pl-PL" in our web.config. But in .rdlc we use "en-EN" - and Report Viewer is changin this also.

    One more interesting "Feature" of new Report Viewer 10.0 is that it changes impersonation level not only in LocalReport.Render function, but also when invoking LocalReport.SetParameter function.

    Ech:( But Guys from Microsoft does not seem to care...

    Monday, September 13, 2010 9:28 PM
  • I just encountered the same problem. I could not find a bug report for this issue on Microsoft Connect so I filed this in bug #610965 on https://connect.microsoft.com/SQLServer.
    Wednesday, October 6, 2010 7:58 AM
  • I wonder what great failure Microsoft did with Report Viewer 10... It's a bugiest thing I've worked with, especially comming from MS. Redicolus! "Well-known" bug is scaling with percentegs - 100% of A4 seems on the screen as twise as bigger... (at least when LocalReport is used), and yes - it's reported already. They said "wait for VS2010 SP1...". So I'm waiting, but nothing comes out.

    Finally, VS2010 isn't a smartest choise for production use, at least for now. I recomend you to turn back to VS2008, and using Report Viewer 9.0. Nothing to do with all these bugs right now.

    Sunday, February 13, 2011 3:22 PM