winforms implementing IReportServerCredentials - Error: Property 'ReportServerCredentials' is 'ReadOnly'
19 Ağustos 2008 Salı 09:58Hi,
I got an error in my win form when I tried to load my reports thru reportserver: below of my code in my frmreportviewer when it loads up it throw an exception that "Property 'ReportServerCredentials' is 'ReadOnly'"
PublicClass frmReportViewer Private Sub frmReportViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote
ReportViewer1.ServerReport.ReportServerUrl = New Uri(_ReportServerURL)
ReportViewer1.ServerReport.ReportPath = "/HRIS_EmployeeInformation/EmployeeList"
ReportViewer1.ServerReport.ReportServerCredentials() = New ReportServerCredentials("administrator", "admin", "WORKGROUP")
This is the class for IReportServerCredentials:
Imports System.Net Public Class ReportServerCredentials
Implements IReportServerCredentials Private _userName As String
Private _password As String
Private _domain As String Public 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.WinForms.IReportServerCredentials.GetFormsCredentials
authCookie = Nothing
userName = password = authority = Nothing
End Function Public ReadOnly Property ImpersonationUser() As System.Security.Principal.WindowsIdentity Implements Microsoft.Reporting.WinForms.IReportServerCredentials.ImpersonationUser Get
End Get End Property Public ReadOnly Property NetworkCredentials() As System.Net.ICredentials Implements Microsoft.Reporting.WinForms.IReportServerCredentials.NetworkCredentials Get
Return New NetworkCredential(_userName, _password, _domain)
End Get End Property
EndClass any one pls help. thank you.
20 Ağustos 2008 Çarşamba 20:49ModeratörUnlike the webforms version of the ReportViewer control which requires you to provide an implementation of the IReportServerCredentials interface, the winforms version of the report viewer implements ReportServerCredentials directly. In your case, you can just assign your NetworkCredential object to ReportViewer.ServerReport.ReportServerCredentials.NetworkCredentials.
- Yanıt Olarak İşaretleyen jeffrey_q 25 Kasım 2009 Çarşamba 11:38
16 Şubat 2012 Perşembe 15:12
That took some digging to find out. Like Brian said ..Winforms behaves differently to Webforms. You cannot assign custom credentials to ReportViewer1.ServerReport.ReportServerCredentials if you use winforms... (is read only...I know weird)....need to assign a network credential object to reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials.
Thus to save yourselves...here is some code ..
reportViewer1.ProcessingMode = ProcessingMode.Remote;
NetworkCredential myCred = new NetworkCredential("MyUserID", "MyPassword", "Domain");}
reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = myCred;
reportViewer1.ServerReport.ReportServerUrl = new Uri("http://xx.xxx.xxx.xx/ReportServer/");
reportViewer1.ServerReport.ReportPath = "/MY_REPORT_DIR/MyReport";