Below is a simple example of using the ReportViewer control with ASP.NET
1. Drag the ReportViewer control on to an empty Web Form.
(If the ReportViewer control isn't in the toolbox, right click and select "Choose Items")
2. Add the Following Code to the Code Behind:
Public Class ReportViewerCredentials
Implements Microsoft.Reporting.WebForms.IReportServerCredentials
Private n As New System.Net.NetworkCredential
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
Return False
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 n
End Get
End Property
Public Sub New(ByVal Username As String, ByVal Password As String)
n.UserName = Username
n.Password = Password
End Sub
End Class
3. Add the following to the Page_Load event, changing the displayname, reportserverurl, username, password and reportpath as appropriate.
If Page.IsPostBack = False Then
With ReportViewer1
.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
With .ServerReport
.DisplayName = "myreport"
.ReportServerUrl = New Uri("http://reportserver/ReportServer")
.ReportServerCredentials = New ReportViewerCredentials("username", "password")
.ReportPath = "/My Reports/myreport"
End With
End With
End If