Friday 15 January 2010

Report viewer control authentication – Part1 – Windows Authentication

Report viewer control, I think everyone knows what it is and how to use it. Today, I want to tell you how to authenticate the report viewer control in ASP.NET web application or windows application.

The report viewer control passing the credentials is same in both windows and web applications. How to pass windows credentials to the report viewer control?

  • Either you can set the <identity impersonation="true" /> or
  • You can directly pass the credentials object to the report viewer control as shown below. If default credentials then
    System.Net.ICredentials credentials = System.Net.CredentialCache.DefaultCredentials;ReportServerCredentials rsCredentials = serverReport.ReportServerCredentials; rsCredentials.NetworkCredentials = credentials;

    But, in some scenarios, you may need to pass the windows credentials dynamically instead of the logged in user credentials. Then it's the time to use NetworkCredentials object. Check below.

    ICredentials credentials = new NetworkCredential("User name", "Password", "Domain");

    Now, assign this credentials object to the report viewer credentials. So, I prefer to not directly give the credentials directly in the code. Instead add them in the web.config and access them in the code.

    I think, you understood it well. Love to hear comments.

No comments:

Post a Comment