Friday, January 15, 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.

4 comments:

  1. Hi Praveen ,
    A lovely post, quiet helpful for us. I have used the credentails as described. But im getting the following error
    "The request failed with the error message: -- Object moved Object moved to href="/hpreporting/Logon.aspx?ReturnUrl=%2fhpreporting%2fReportExecution2005.asmx">here --. "

    Please help!!
    Thanks in advance!!

    ReplyDelete
  2. Hi Priyanthi,
    That's interesting. Are you sure the web service url you are using for report server working? I believe the url is the problem not the code.
    Please check once that,
    1. the report server you are referencing is working properly and the url of asmx is also not seems to be correct.
    2. Check once the credentials.

    Let me know, if both of the cases passed, we will analyze it further.

    thanks
    -Praveen.

    ReplyDelete
  3. Hey Praveen, Thanks for the reply!!! Sorry for late response.

    1. The report Server is working properly , we are able to deploy reports and view them.
    2. We can access the reports only after giving the proper credentails in the authentication box.
    The point here to be noted is Report Server is configured to windows authentication mode.

    I would like to view the reports with out changing the Authentication mode on the Report Server.

    Hope I am clear!

    ReplyDelete