我已经为外部报告使用实现了 SSRS 2005 自定义安全扩展,但是我在登录用户会话功能方面遇到了一些困难。
我在后面的.aspx代码中登录报表服务器并获取报表列表,因为我必须将参数添加到用户看不到的报表中。我遇到的问题是当用户查看报告并想要返回报告列表页面时,用户得到“未收到验证票”错误。
如果我只是在每次页面加载/重新加载时将用户登录到报表服务器,我可以解决这个问题,但我要警惕这种方法。自定义示例附带的报告服务器类似乎没有我可以设置或获取的表单身份验证凭据属性。
有没有办法一次登录到报表服务器并在请求之间保持用户的会话?如果是这样,如何?
下面是我的一些代码
Dim cookie As HttpCookie
Public Property ReportServer() As ReportServerProxy
Get
Dim _reportServer As ReportServerProxy
If Not ViewState("rptServer") Is Nothing Then
_reportServer = ViewState("rptServer")
Else
_reportServer = New ReportServerProxy()
End If
Return _reportServer
End Get
Set(ByVal value As ReportServerProxy)
ViewState("rptServer") = value
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
cookie = Request.Cookies("sqlAuthCookie")
'If Not IsPostBack Then
GetReports()
'End If
End Sub
Protected Sub GetReports()
Dim passwordVerified As Boolean = False
Using server As ReportServerProxy = Me.ReportServer
Try
' Set the report server and log in.
server.Url = AuthenticationUtilities.GetReportServerUrl("svrname")
'////////////////////////////////////////////////////////
' this is where my problem is!
'///////////////////////////////////////////////////////
server.LogonUser("username", "password", Nothing)
passwordVerified = True
Catch
Throw New Exception("An error occured while trying to access the report. Please contact website support for further assistance.")
End Try
If passwordVerified = True Then
Dim items As Microsoft.SqlServer.ReportingServices2005.CatalogItem() = server.ListChildren("/", True)
' Add select option to ddl.
ddlReports.Items.Add(New ListItem("-- Select A Report --", ""))
'Get all report links that user has available.
For Each cItem As Microsoft.SqlServer.ReportingServices2005.CatalogItem In items
If cItem.Type = Microsoft.SqlServer.ReportingServices2005.ItemTypeEnum.Report Then
Dim lItem As New ListItem()
lItem.Text = cItem.Name
lItem.Value = cItem.Path
ddlReports.Items.Add(lItem)
End If
Next
Else
End If
Me.ReportServer = server
End Using
End Sub
Protected Sub ddlReports_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlReports.SelectedIndexChanged
ReportViewer1.Visible = False
If cookie Is Nothing Then
'************************************************//
'************************************************//
' NEED TO CHANGE URL BELOW!
'************************************************//
'************************************************//
'Response.Redirect("/appFolder/logon.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.RawUrl));
Dim ex As New Exception("An error occured while trying to view the report. Please contact the website administrator for further assistance.")
Throw ex
ElseIf Not cookie Is Nothing And Not String.IsNullOrEmpty(ddlReports.SelectedValue) Then
'Establish connection with reporting server, verify credentials and pull report.
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
ReportViewer1.ServerReport.ReportServerUrl = New Uri(ConfigurationManager.AppSettings("ssrsRptSvr").ToString())
ReportViewer1.ServerReport.ReportPath = ddlReports.SelectedValue
'Set SSRS report credentials.
Dim authCookie As New Cookie(cookie.Name, cookie.Value)
authCookie.Domain = ConfigurationManager.AppSettings("DomainName").ToString()
ReportViewer1.ServerReport.ReportServerCredentials = New RptServerCreds(authCookie)
'Add account id or company parameter to report.
Dim parms As New List(Of Microsoft.Reporting.WebForms.ReportParameter)()
parms.Add(New Microsoft.Reporting.WebForms.ReportParameter("AccountId", MySession.AccountID, False))
parms.Add(New Microsoft.Reporting.WebForms.ReportParameter("GroupId", "2", False))
Me.ReportViewer1.ServerReport.SetParameters(parms)
ReportViewer1.ServerReport.Refresh()
ReportViewer1.Visible = True
End If
End Sub