reportviewer: code the windows credentials

Rate It (1)

Last post 06-15-2009 8:03 AM by gauriashitre_12. 33 replies.

Sort Posts:

  • reportviewer: code the windows credentials

    03-07-2006, 5:56 PM
    • Member
      25 point Member
    • ze_pi
    • Member since 06-22-2005, 4:22 PM
    • Posts 5

    I have bought a hosting service for reporting services. The server definitions are set to windows authentication.

    I'm using a small application and each time I access a report, a windows prompt asks for the username and password. I would like to avoid this message.

    How should I pass the credentials through this application and the reportviewer control (which I use) to the server in order to avoid having to insert the user details in the prompt. This application is to be used by several users and they shouldn't need to insert the account's information.

    thank you for a quick reply.

  • Re: reportviewer: code the windows credentials

    03-08-2006, 9:51 AM
    • Contributor
      6,537 point Contributor
    • bitmask
    • Member since 07-29-2003, 3:18 PM
    • Citizen of the Earth
    • Posts 1,228

    There is no way to add credentials to the report viewer.

    Does your local login map to a login on the server at all? If so, Internet Explorer only sends credentials automatically to servers in the Intranet zone, but you can have it automatically send credentials to your host.

    You could mark your host as a trusted site (Tools -> Internet Options -> Security), and then tell IE to send credentials automatically to sites in the trusted zone. With Trusted Zones highlighted in the tab, click "Custom Level". Scroll down to the bottom and select "automatic login with current username and password".

    Scott
    http://www.OdeToCode.com/blogs/scott/
  • Re: reportviewer: code the windows credentials

    08-10-2006, 4:08 PM
    • Member
      29 point Member
    • CodeSalad
    • Member since 12-09-2005, 4:12 PM
    • Spokane, WA
    • Posts 7
    This can be done.  First create a class called ReportServerCredentials that implements the IReportServerCredentials interface.  You will need to import System.Net and Microsoft.Reporting.WebForms to this class.  Overload the New and GetFormsCredentials methods and the NetworkCredentials and ImpersonationUser properties.  Here's a class that I use:

    Imports Microsoft.VisualBasic
    Imports Microsoft.Reporting.WebForms
    Imports System.Net

    Public Class ReportServerCredentials
        Implements IReportServerCredentials

        Private _userName As String
        Private _password As String
        Private _domain As String

        Public Sub New(ByVal userName As String, ByVal password As String, ByVal domain As String)
            _userName = userName
            _password = password
            _domain = domain
        End Sub

        Public ReadOnly Property ImpersonationUser() As System.Security.Principal.WindowsIdentity Implements Microsoft.Reporting.WebForms.IReportServerCredentials.ImpersonationUser
            Get
                Return Nothing
            End Get
        End Property

        Public ReadOnly Property NetworkCredentials() As ICredentials Implements Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentials
            Get
                Return New NetworkCredential(_userName, _password, _domain)
            End Get
        End Property

        Public Function GetFormsCredentials(ByRef authCookie As System.Net.Cookie, ByRef userName As String, ByRef password As String, ByRef authority As String) As Boolean Implements Microsoft.Reporting.WebForms.IReportServerCredentials.GetFormsCredentials
            userName = _userName
            password = _password
            authority = _domain
            Return Nothing
        End Function
    End Class

    Next, in the OnLoad of your page with the ReportViewer control, create a new instance of your ReportServerCredentials (I use values stored in AppSettings).  Then assign your object to the ReportViewer control's ServerReport.ReportServerCredentials property. 

    Dim cred As New ReportServerCredentials(ConfigurationManager.AppSettings("MyStoredUser"),_
        ConfigurationManager.AppSettings("MyStoredPassword"), _
        ConfigurationManager.AppSettings("MyStoredDomain"))
       
        MyReportViewerControl.ServerReport.ReportServerCredentials = cred

    A few things can break though-- referenced images on your reports won't render, and you can't use integrated security in your SSRS data sources, unless the account you are impersonating has access to the data as well as SSRS.

    -Kelly

    "Well of course, everything looks bad if you remember it." - Homer Simpson
  • Re: reportviewer: code the windows credentials

    03-09-2007, 3:16 PM
    • Member
      47 point Member
    • twells
    • Member since 09-14-2006, 2:11 PM
    • Posts 14

    Code Salad,

    My immeasurable thanks. After three days of searching, your solution was the one that finally got my reports running

  • Re: reportviewer: code the windows credentials

    08-21-2007, 5:26 PM
    • Member
      726 point Member
    • danyeung
    • Member since 06-22-2005, 5:37 PM
    • Posts 354

    It seems CodeSalad's code worked.  Can someone explain how it works?  Where do I add the code?  I am having the same problem.  I am using Framework 2.0.  Thanks.

     DanYeung

  • Re: reportviewer: code the windows credentials

    08-22-2007, 1:48 AM
    • Contributor
      3,634 point Contributor
    • akjoshi
    • Member since 05-06-2006, 1:23 PM
    • INDIA
    • Posts 614
    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question; this ensures the right forum member gets credit for being helpful (and makes search more relevant too).
  • Re: reportviewer: code the windows credentials

    08-22-2007, 9:43 AM
    • Participant
      1,352 point Participant
    • Karenros
    • Member since 11-08-2006, 2:54 PM
    • Charlotte, NC
    • Posts 1,170

    Danyeng,

     U have to add a new class file in the app_Code directory

  • Re: reportviewer: code the windows credentials

    08-23-2007, 1:21 PM
    • Member
      726 point Member
    • danyeung
    • Member since 06-22-2005, 5:37 PM
    • Posts 354

    The links and the sample code are very helpful.  I still need more help on this.  How do I get the ReportViewer control?  I am opening the report without using ReportView control.  I added the attribute to the button to open the report with Javascript.  If I use the ReportViewer control, do I have to open the report differently and how?  Thanks.

    DanYeung

  • Re: reportviewer: code the windows credentials

    08-23-2007, 1:55 PM
    • Participant
      1,352 point Participant
    • Karenros
    • Member since 11-08-2006, 2:54 PM
    • Charlotte, NC
    • Posts 1,170

    this is how u doing it.

    create a new aspx page and add the report viewer control to ur page by going View Menu -> Toolbox  and in the toolbox look under Data.. and then in the properties window, Select the processingmode i.e Remote or local and also specify the report path...

    and then in the aspx.vb page in Page_Load sub  give this code.

     

     

    ReportViewer1.ProcessingMode = ProcessingMode.Remote
                ReportViewer1.ShowCredentialPrompts = True
                'ReportViewer1.ShowExportControls = False
    
                ReportViewer1.ServerReport.ReportServerCredentials = New ReportServerCredentials()
                ReportViewer1.ServerReport.ReportServerUrl = New Uri("http://IPAddress/ReportServer")
                ReportViewer1.ServerReport.ReportPath = "/FolderName/Mainrdlfilename"
                ReportViewer1.ServerReport.Refresh()
     

    ReportViewer1.ServerReport.ReportServerCredentials = New ReportServerCredentials() ---- ReportServerCredentials is the base class name of the class that u put in the app_code folder

    Hope this helps.

    Regards,

    Karen

  • Re: reportviewer: code the windows credentials

    08-23-2007, 4:48 PM
    • Member
      726 point Member
    • danyeung
    • Member since 06-22-2005, 5:37 PM
    • Posts 354

    Thanks Karen.  I am getting closer.  I received the following error:

    The path of the item '/Pages/ReportViewer.aspx?nsPortalReports.rptIssuesByRole&rs:Command=Render&intProjectID=119&RunBy=DanYeung' is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash. (rsInvalidItemPath)

    The report is located in the different project with the same solution.  nsPortalReports is the project name and rptIssuesByRole is the report name.  What is wrong in the path?  Thanks.

    DanYeung

  • Re: reportviewer: code the windows credentials

    08-23-2007, 5:34 PM
    • Participant
      1,352 point Participant
    • Karenros
    • Member since 11-08-2006, 2:54 PM
    • Charlotte, NC
    • Posts 1,170

    is ur report stored in the report server? and if ur reports are stored in the report server is there any kinda directory structure in it... 

    if u answer this questions may be i can give u a better answer.

    Regards

    Karen

  • Re: reportviewer: code the windows credentials

    08-23-2007, 8:18 PM
    • Member
      726 point Member
    • danyeung
    • Member since 06-22-2005, 5:37 PM
    • Posts 354

    Yes, I deployed the reports to the report server.  Thanks.

    DanYeung

  • Re: reportviewer: code the windows credentials

    08-23-2007, 10:42 PM
    • Participant
      1,352 point Participant
    • Karenros
    • Member since 11-08-2006, 2:54 PM
    • Charlotte, NC
    • Posts 1,170

    are u able to run the reports using the report viewer...

     Since ur reports are in the report server just give the path as i have given and it should work... if u need to pass any parameters to the report also let me know  i will help u out..

    Regards

    Karen

  • Re: reportviewer: code the windows credentials

    08-24-2007, 11:03 AM
    • Member
      726 point Member
    • danyeung
    • Member since 06-22-2005, 5:37 PM
    • Posts 354

    How do I run the report using ReportViewer?  Yes, I have to pass parameters.  So I am not supposed pass parameters in the ReportPath?  Is my path correct?

    ReportViewer1.ServerReport.ReportPath = "/Pages/ReportViewer.aspx?nsPortalReports.rptIssuesByRole&rs:Command=Render&intProjectID=" & cboProject.SelectedValue & "&RunBy=" & Session("strEmployeeName")

    Thanks.

    DanYeung

  • Re: reportviewer: code the windows credentials

    08-24-2007, 11:38 AM
    • Participant
      1,352 point Participant
    • Karenros
    • Member since 11-08-2006, 2:54 PM
    • Charlotte, NC
    • Posts 1,170

    your report Path doesnt Look right to me.

     Instead of specifying the report Path... Specify a the ReportServerURL so that u can access ur report server directly. and the url will be http://IpAddress/ReportServer.

     

    take a look at this code as to how to specify the parameters and the report Path

     

    ReportViewer1.ProcessingMode = ProcessingMode.Remote
                ReportViewer1.ShowCredentialPrompts = True
                ReportViewer1.ShowExportControls = False
    
                ReportViewer1.ServerReport.ReportServerCredentials = New ReportServerCredentials()
                ReportViewer1.ServerReport.ReportServerUrl = New Uri("http://IPAddress/ReportServer")
    
    
                s = CType(PreviousPage.FindControl("ddlReportType"), DropDownList).SelectedItem.Value
                If (s = "/Statements/StatementMain") Then
    
                    ReportViewer1.ServerReport.ReportPath = "/Statements/StatementMain"
                    Dim ClientID As String = Session("ClientId")
    
                    Dim param(0) As Microsoft.Reporting.WebForms.ReportParameter
                    'param(0) = New Microsoft.Reporting.WebForms.ReportParameter("PeriodId", "")
                    param(0) = New Microsoft.Reporting.WebForms.ReportParameter("ClientId", ClientID, False)
    
                    ReportViewer1.ServerReport.SetParameters(param)
    ReportViewer1.ServerReport.Refresh()
            End If
     
    u can omit the parameters so that u can directly set them while u run the reports.
    Hope this helps.
     

    Regards,

    Karen

Page 1 of 3 (34 items) 1 2 3 Next >