Trying to use ReportViewer webcontrol with Forms Authentication and getting rsLogonFailed error

Posted on 2008-11-19
Last Modified: 2012-05-05
I have reconfigured reporting services to use Forms Authentication against our membership database.  The report manager and report server websites that come out of the box with SSRS2005 authenticate and render all reports as expected.

The problem is when I try to render the report in the reportviewer webcontrol on a different website.  The error the control displays is "Logon failed. (rsLogonFailed) " and there is no error log generated in log folder.

I have included the code I am using to bind the reportviewer control and the implimentation of IReportServerCredentials class to pass the forms cookie to the report server.

I have read several websites and cannot seem to identify where I am going wrong here, any help would be appreciated.

    Private Sub LoadReport()

        Dim lManualConfig As New ManualConfigs

        Dim lStrItemPath As String = Request("ItemPath") & ""

        ucReportViewer.AsyncRendering = False

        ucReportViewer.ProcessingMode = ProcessingMode.Remote

        ucReportViewer.ServerReport.ReportServerUrl = New Uri(lManualConfig.ReportServerUrl)

        ucReportViewer.ServerReport.ReportPath = lStrItemPath

        ucReportViewer.ServerReport.ReportServerCredentials = New MyReportServerCredentials


    End Sub


Public NotInheritable Class MyReportServerCredentials

    Implements IReportServerCredentials

    Public ReadOnly Property ImpersonationUser() As WindowsIdentity _

            Implements IReportServerCredentials.ImpersonationUser


            'Use the default windows user.  Credentials will be

            'provided by the NetworkCredentials property.

            Return Nothing

        End Get

    End Property

    Public ReadOnly Property NetworkCredentials() As ICredentials _

            Implements IReportServerCredentials.NetworkCredentials


            Return Nothing

        End Get

    End Property

    Public Function GetFormsCredentials(ByRef authCookie As Cookie, _

                                        ByRef userName As String, _

                                        ByRef password As String, _

                                        ByRef authority As String) _

                                        As Boolean _

            Implements IReportServerCredentials.GetFormsCredentials

        Dim lManualConfig As New ManualConfigs

        Dim lHttpCookie As HttpCookie = HttpContext.Current.Request.Cookies(FormsAuthentication.FormsCookieName)

        userName = password = authority = Nothing

        If IsNothing(lHttpCookie) Then


        End If

        Dim lNetCookie As New Cookie

        lNetCookie.Name = lHttpCookie.Name

        lNetCookie.Value = lHttpCookie.Value

        lNetCookie.Domain = HttpContext.Current.Request.ServerVariables("SERVER_NAME").ToUpper

        lNetCookie.Expires = lHttpCookie.Expires

        lNetCookie.Path = lHttpCookie.Path

        lNetCookie.Secure = lHttpCookie.Secure

        Return True

    End Function

End Class

Open in new window

Question by:Merion
    1 Comment

    Accepted Solution

    I solved this problem today, for anyone interested or having the same issue.  It turns out the cookie being pulled via this statement:

            Dim lHttpCookie As HttpCookie = HttpContext.Current.Request.Cookies(FormsAuthentication.FormsCookieName)

    does not return the cookie validates against the reportserver (I am not sure why however the cookie obtained this way does not have the domain value set).

    To resolve this I changed that line to this:

    Dim lHttpCookie As HttpCookie = FormsAuthentication.GetAuthCookie(CurrentUsername, True)

    and also updated the following line:

            lNetCookie.Domain = HttpContext.Current.Request.ServerVariables("SERVER_NAME").ToUpper


            lNetCookie.Domain = lHttpCookie.Domain

    and now the reportviewer properly authenticates and renders the requested report.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
    When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now