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”

ส่วน 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
            Return Nothing
        End Get
    End Property

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

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

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


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


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s