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?
MerionConnect With a Mentor Author 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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.