外部レポート用に SSRS 2005 カスタム セキュリティ拡張機能を実装しましたが、ログオン ユーザー セッション機能に問題があります。
.aspx コード ビハインドでレポート サーバーにログオンし、レポート リストを取得します。これは、ユーザーには表示されないパラメーターをレポートに追加する必要があるためです。私が遭遇した問題は、ユーザーがレポートを表示し、レポート リスト ページに戻りたいときに、ユーザーが「Auth ticket was not received」エラーを取得することです。
ページの読み込み/再読み込みのたびにユーザーをレポート サーバーにログインさせるだけで、これを回避できますが、その方法には注意が必要です。カスタム サンプルに付属する reportserver クラスには、設定または取得できるフォーム認証資格情報プロパティがないようです。
レポート サーバーに一度ログインして、要求間でユーザーのセッションを維持する方法はありますか? もしそうなら、どのように?
以下は私のコードの一部です
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