ตามตัวอย่างนี้
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 แทน
ไม่มีความคิดเห็น:
แสดงความคิดเห็น