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

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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MerionAuthor Commented:
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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.