?
Solved

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

Posted on 2008-11-19
1
Medium Priority
?
1,384 Views
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 ASP.net 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
        ucReportViewer.ServerReport.Refresh()
 
    End Sub
 
...
 
Public NotInheritable Class MyReportServerCredentials
    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 ICredentials _
            Implements IReportServerCredentials.NetworkCredentials
        Get
 
            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
            HttpContext.Current.Response.Redirect(lManualConfig.UrlSsLogin)
        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

0
Comment
Question by:Merion
1 Comment
 

Accepted Solution

by:
Merion earned 0 total points
ID: 23009349
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

to:

        lNetCookie.Domain = lHttpCookie.Domain

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

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

850 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