Reporting Services 2008: asking for username and password

A co-worker was developing some reports and embedding them on an ASP.Net webpage using Reporting Services 2005. Everything was working OK.

However, when I had to put the webapp into the production server, it was always prompting for username/password.

The production server is a Windows 2008 server, having Reporting Services 2008.

As you may know, Reporting Services 2008 doesn’t use IIS to provide access to the ReportManager or ReportServer, so you can’t use anonymous login.

So, in this sense it’s a bit more secure than Reporting Services 2005. But it’s harder to deploy.

The username/password it’s asking for is the Windows username/password.

I would never reveal this to final users so I looked for a solution.

I came to this page and found the solution:

http://forums.asp.net/p/1202398/2103516.aspx

Basically, you have to store username/password on AppSettings section on your web.config and create a class on App_Code to read these network credentials so Reporting Services don’t ask users for Windows username/password.

On your web.config:

<appSettings>
<add key="UserName" value="UserName"/>
                <add key="Password" value="Password"/>
                <add key="SERVERNAME" value="SERVERNAME"/>
</appSettings>

 

The class ReportServerCredentials is:

 

Imports Microsoft.VisualBasic
Imports Microsoft.Reporting.WebForms
Imports System.Security.Principal

Public NotInheritable Class ReportServerCredentials
    Implements IReportServerCredentials

    Public ReadOnly Property ImpersonationUser() As WindowsIdentity _
            Implements IReportServerCredentials.ImpersonationUser
        Get

            'Use the default windows user.  Credentials will be
            'provided by the NetworkCredentials property.
            Return Nothing

        End Get
    End Property

    Public ReadOnly Property NetworkCredentials() As Net.ICredentials _
            Implements IReportServerCredentials.NetworkCredentials
        Get

            'Read the user information from the web.config file.  
            'By reading the information on demand instead of storing
            'it, the credentials will not be stored in session,
            'reducing the vulnerable surface area to the web.config
            'file, which can be secured with an ACL.

            'User name
            Dim userName As String = _
                ConfigurationManager.AppSettings("UserName")

            If (String.IsNullOrEmpty(userName)) Then
                Throw New Exception("Missing user name from web.config file")
            End If

            'Password
            Dim password As String = _
                ConfigurationManager.AppSettings("Password")

            If (String.IsNullOrEmpty(password)) Then
                Throw New Exception("Missing password from web.config file")
            End If

            'Domain
            Dim domain As String = _
                ConfigurationManager.AppSettings("SERVERNAME")

            If (String.IsNullOrEmpty(domain)) Then
                Throw New Exception("Missing domain from web.config file")
            End If

            Return New Net.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 IReportServerCredentials.GetFormsCredentials

        authCookie = Nothing
        userName = Nothing
        password = Nothing
        authority = Nothing

        'Not using form credentials
        Return False

    End Function

End Class

 

Then, you can call your Report the following way:

 

            reportViewer.ProcessingMode = ProcessingMode.Remote
            Dim serverReport As ServerReport
            serverReport = reportViewer.ServerReport
            'Set the report server URL and report path
            serverReport.ReportServerUrl = _
                New Uri("http://192.168.10.215/ReportServer_SQL2008")
                serverReport.ReportPath = _
                "/ReportRRHH/rptFichaSocial"
            'Read network credentials from your web.config using ReportServerCredentials class on App_Code
            serverReport.ReportServerCredentials = New ReportServerCredentials()
            'Create the sales order number report parameter
            Dim P_IDPERSONAL As New ReportParameter()
            P_IDPERSONAL.Name = "P_IDPERSONAL"
            P_IDPERSONAL.Values.Add("123456")

            'Set the report parameters for the report
            Dim parameters() As ReportParameter = {P_IDPERSONAL}
            serverReport.SetParameters(parameters)

References:

http://forums.asp.net/p/1202398/2103516.aspx

http://64.4.11.252/es-es/library/aa337091%28SQL.100%29.aspx

http://stackoverflow.com/questions/671694/passing-credentials-to-sql-report-server-2008

http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/5aa7eee7-d4a7-427a-ab8d-7a3d4d4f0bf3/

One response to this post.

  1. No creia leer uuո post asi en este blog ,en caambio hoy estoy realmente satisfecho con
    el de hoy

    Responder

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: