我已经实现了SSRS 2005自定义安全扩展以供外部报告使用,但是我在登录用户会话功能方面遇到了一些困难。
我在后面的.aspx代码中登录到报表服务器并获取报表列表,因为我必须在报表中添加用户看不到的参数。我遇到的问题是当用户查看报告并想要返回到报告列表页面时,用户会收到“未收到身份验证票证”错误。
如果我只是在每次加载/重新加载页面时将用户登录到报表服务器,我可以解决这个问题,但我对此方法持谨慎态度。自定义示例附带的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
答案 0 :(得分:0)
尝试使用以下方法设置返回的身份验证。有一种COM方法可以将身份验证令牌设置为Internet Explorer。参考System.runtime.interopservices。
<DllImport("wininet.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function InternetSetCookie(lpszUrl As String, _
lpszCookieName As String, lpszCookieDataAs String) As Boolean
End Function