Authenticate Reporting Service (SSRS) ReportServerCredentials


โดนปกติเราจะใช้การ authenticate reporting servcie ด้วย method ReportServerCredentials
ตามตัวอย่างนี้

        ReportViewer1.ServerReport.ReportServerCredentials = New ReportCredentials(“Pokpong”, “Kak”, “DomainName”)
        ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
        ReportViewer1.ServerReport.ReportServerUrl = New System.Uri(strUrl)
        ReportViewer1.ServerReport.ReportPath = “/CSWExternalSector/RptExtBOPBath”
        ‘ReportViewer1.ServerReport.SetParameters(parameters)
        ReportViewer1.ServerReport.Refresh()

ส่วน class ReportCredentials

Public Class ReportCredentials
    Implements Microsoft.Reporting.WebForms.IReportServerCredentials


    Dim _userName, _password, _domain As String


    Sub New(ByVal userName As String, ByVal password As String, ByVal domain As String)
        _userName = userName
        _password = password
        _domain = domain
    End Sub
    Public Function GetFormsCredentials(ByRef authCookie As System.Net.Cookie, ByRef userName As String, ByRef password As String, ByRef authority As String) As Boolean Implements Microsoft.Reporting.WebForms.IReportServerCredentials.GetFormsCredentials


        userName = _userName
        password = _password
        authority = _domain
        authCookie = New System.Net.Cookie(“.ASPXAUTH”, “.ASPXAUTH”, “/”, “Domain”)
        Return True
    End Function


    Public ReadOnly Property ImpersonationUser() As System.Security.Principal.WindowsIdentity Implements Microsoft.Reporting.WebForms.IReportServerCredentials.ImpersonationUser
        Get
            Return Nothing
        End Get
    End Property


    Public ReadOnly Property NetworkCredentials() As System.Net.ICredentials Implements Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentials
        Get
            Return New System.Net.NetworkCredential(_userName, _password, _domain)
        End Get
    End Property
End Class

ปัญหาของการทำ Credential แบบนี้คือมันต้อง hard code username , password ลงไปเราจะทำยังไงละให้user นั้น dynamic ตาม user profile ของเครื่อง

เราแก้ปัญหาด้วยการ ไม่ใช้
ReportServerCredentials

แล้วทำการเิพิ่ม

identity impersonate=”true”
   
ลงไปใน web.config แทน

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: