Friday, March 23, 2012

ReportServerCredentials is readonly?

I'm trying to use this code:
ReportViewer1.ServerReport.ReportServerCredentials = New
ReportViewerCredentials("TestUser", "TestPW", "")
but VS2008 is complaining that ReportServerCredentials is readonly.
Not according to the documentation, so something else is wrong I
guess?
Any help appreciated. I'm done banging my head on the desk and will go
home for the night.
This is the class:
Imports Microsoft.VisualBasic
Imports Microsoft.Reporting.WinForms
Imports System.Security.Principal
Public Class ReportViewerCredentials
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 ReadOnly Property ImpersonationUser() As
System.Security.Principal.WindowsIdentity Implements
Microsoft.Reporting.WinForms.IReportServerCredentials.ImpersonationUser
Get
Return Nothing
End Get
End Property
Public ReadOnly Property NetworkCredentials() As
System.Net.ICredentials Implements
Microsoft.Reporting.WinForms.IReportServerCredentials.NetworkCredentials
Get
Return New Net.NetworkCredential(_userName, _password, _domain)
End Get
End Property
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
userName = _userName
password = _password
authority = _domain
Return Nothing
End Function
End ClassImports System.Net
Imports System.Security.Principal
Imports Microsoft.Reporting.WebForms
Imports System.Web
Imports System.Collections.Specialized
Imports System.Collections.ObjectModel
Imports System.Collections
Imports System.Text
Imports System.Configuration
Namespace ReportConnection
<Serializable()> _
Public NotInheritable Class MyReportServerCredentials
Implements IReportServerCredentials
Public ReadOnly Property ImpersonationUser() As WindowsIdentity _
Implements IReportServerCredentials.ImpersonationUser
Get
'Use the default windows user. Credentials will be
'provided by the NetworkCredentials property.
Return Nothing
End Get
End Property
Public ReadOnly Property NetworkCredentials() As ICredentials _
Implements IReportServerCredentials.NetworkCredentials
Get
'Read the user information from the web.config file.
'By reading the information on demand instead of storing
'it, the credentials will not be stored in session,
'reducing the vulnerable surface area to the web.config
'file, which can be secured with an ACL.
Dim appSettings As NameValueCollection = _
ConfigurationManager.AppSettings
'User name
Dim userName As String = _
ConfigurationManager.AppSettings("MyReportViewerUser")
If (String.IsNullOrEmpty(userName)) Then
Throw New Exception("Missing user name from web.config
file")
End If
'Password
Dim password As String = _
ConfigurationManager.AppSettings("MyReportViewerPassword")
If (String.IsNullOrEmpty(password)) Then
Throw New Exception("Missing password from web.config
file")
End If
'Domain
Dim domain As String = _
ConfigurationManager.AppSettings("MyReportViewerDomain")
If (String.IsNullOrEmpty(domain)) Then
Throw New Exception("Missing domain from web.config file")
End If
Return New NetworkCredential(userName, password, domain)
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
'Not using form credentials
Return False
End Function
End Class
End Namespace

No comments:

Post a Comment