401未使用Azure中的SSRS ReportViewer进行授权

时间:2018-01-20 15:50:49

标签: asp.net azure reporting-services

我们目前有一个自托管的ASP.NET Web Forms应用程序,它使用SSRS报告后端。使用ReportViewer控件10.0.0.0访问报告。我们有业务需要将此工作负载转移到Azure。

我们将数据库迁移到SQL Azure并设置Azure网站(Web App),用于维护数据库中数据的应用程序部分工作正常。我们设置了一个运行SQL2016的VM,配置了SSRS并上传了我们的报告RDL和DataSources。报告在SSRS门户网站上运行良好。

当我们尝试通过Web应用程序访问报告时,我们得到的是401:未经授权。我们在SSRS服务器上使用本地Windows登录进行身份验证(我们尝试了SQL服务器登录,结果相同)。 Windows登录已在SSRS门户中设置,可以访问报告并可通过SQL Server访问数据库。 Web应用程序没有使用模拟(我明确地将其关闭以确定)。

我使用Windows版本的Report viewer控件编写了一个快速的Windows窗体应用程序,这很好用。查看器控件的设置代码基本相同。我已尝试使用和不在本地帐户的凭据中指定“计算机名称”的Web版本。

我在下面的Web App中包含了设置代码。在这一点上,我不认为这是一个代码问题,就像Web设置问题一样。任何帮助或指示将不胜感激。

埃里克。

Dim myCreds As System.Net.CredentialCache = New System.Net.CredentialCache
Dim storedParams As Microsoft.Reporting.WebForms.ReportParameterCollection = CType(Session("Current_ReportParams"), Microsoft.Reporting.WebForms.ReportParameterCollection)
With ReportViewer1
.Reset()
.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
.ServerReport.ReportServerUrl = New Uri(ReportServer) 'Report Server URL
.ServerReport.ReportPath = String.Format("{0}/{1}", ReportPath, ReportFileName) 'Report Name
.ServerReport.SetParameters(storedParams)
myCreds.Add(New Uri(ReportServer), "Basic", New System.Net.NetworkCredential("user", "password", "machine"))
.ServerReport.ReportServerCredentials = myCreds
.ShowParameterPrompts = False
.SizeToReportContent = True
.ServerReport.Refresh()
End With

1 个答案:

答案 0 :(得分:0)

我会将此作为答案而不是评论发布。在使用Microsoft支持时,我稍微修改了我的代码。我添加了一个实现IReportServerCredentials的类,该类使用用户名和密码返回NetworkCredential。我们仍然坚持得到401错误。我们开始运行网络跟踪,并注意到凭据没有像我们预期的那样出现在跟踪中。然而,我们确实看到NTLM否定发生并且失败。

我们验证了rsReportServer.config已启用基本身份验证并禁用NTLM和Kerberos身份验证只是为了安全。仍然以401失败。

经过MS和许多Bingle搜索的几次来回,我们发现.ServerReport.SetParameters方法调用了SSRS服务器。我们之后设置了.ServerReport.ReportServerCredentials。只需在.ServerReport.SetParameters方法之前移动.ServerReport.ReportServerCredentials即可解决问题。更新的代码如下。)

因此,这是编程错误,而不是配置错误。这将影响与调用ReportViewer控件的网站不在同一域中的任何SSRS实例。

Imports Microsoft.Reporting.WebForms
Imports System.Net
Imports System.Security.Principal
Public Class ucReportPreview
    Inherits System.Web.UI.UserControl


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load



        If Not IsPostBack Then
            'gets the report viewer control from the session if it exists
            If Not Session("Current_ReportFileName") Is Nothing Then
                Dim sysOpt As New SystemOption
                'Dim ReportServer As String = sysOpt.LookupValueByShortDescription("ReportServer")
                'Dim ReportPath As String = sysOpt.LookupValueByShortDescription("ReportPath")
                'Dim ReportFileName As String = Session("Current_ReportFileName").ToString
                Dim ReportServer As String = "http://logsdon-ssrs/ReportServer"
                'Dim ReportPath As String = "/InfoRail V5/IR-20141118"
                Dim ReportPath As String = "/userinfo"
                Dim ReportFileName As String = "Certification Requirements Due (By Employee)"
                Dim myCreds As IReportServerCredentials = New MyReportServerCredentials("<userName>", "<password>", "<machine-or-domainName>")

                If Not Session("Current_ReportParams") Is Nothing Then

                    Dim storedParams As Microsoft.Reporting.WebForms.ReportParameterCollection = CType(Session("Current_ReportParams"), Microsoft.Reporting.WebForms.ReportParameterCollection)
                    With ReportViewer1
                        .Reset()
                        .ServerReport.ReportServerCredentials = myCreds
                        .ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
                        .ServerReport.ReportServerUrl = New Uri(ReportServer) 'Report Server URL
                        .ServerReport.ReportPath = String.Format("{0}/{1}", ReportPath, ReportFileName) 'Report Name
                        .ServerReport.SetParameters(storedParams)
                        .ShowParameterPrompts = False
                        .SizeToReportContent = True
                        .ServerReport.Refresh()
                    End With

                Else

                    Dim storedParams As Microsoft.Reporting.WebForms.ReportParameterCollection = CType(Session("Current_ReportParams"), Microsoft.Reporting.WebForms.ReportParameterCollection)
                    With ReportViewer1
                        .Reset()
                        .ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
                        .ServerReport.ReportServerUrl = New Uri(ReportServer) 'Report Server URL
                        .ServerReport.ReportPath = String.Format("{0}/{1}", ReportPath, ReportFileName) 'Report Name
                        .ServerReport.ReportServerCredentials = myCreds
                        .ShowParameterPrompts = True
                        .SizeToReportContent = True
                        .ServerReport.Refresh()
                    End With

                End If
            End If




        End If



    End Sub

    Private Sub Page_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed

        'destroys the report viewer control in the session
        Session("Current_ReportParams") = Nothing

    End Sub

    Protected Function GetReportName(Reportid As Integer) As String
        Dim retval As String = String.Empty
        'Dim rt As New ReportTableBLL(System.Web.HttpContext.Current.Session("ConnectionString"))
        'retval = rt.GetReportfilenameByReportid(Reportid)
        Return retval
    End Function

End Class

Public NotInheritable Class MyReportServerCredentials
    Implements IReportServerCredentials
    Private _userName As String
    Private _password As String
    Private _domainName As String

    Public ReadOnly Property ImpersonationUser() As WindowsIdentity Implements IReportServerCredentials.ImpersonationUser
        Get
            Return Nothing

        End Get
    End Property
    Public ReadOnly Property NetworkCredentials() As ICredentials Implements IReportServerCredentials.NetworkCredentials
        Get
            Return New NetworkCredential(_userName, _password, _domainName)
        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

        authCookie = Nothing
        userName = Nothing
        password = Nothing
        authority = Nothing

        Return False

    End Function

    Public Sub New(userName As String, password As String, domainName As String)
        _userName = userName
        _password = password
        _domainName = domainName
    End Sub


End Class