Marie Ramos

This can't be rocket science. In RS 2000, I could set a credential like this:

rs.Credentials = New System.Net.NetworkCredential(repSvcUserID, repSvcPwd, repSvcDomain)

What is the equivalent to this in RS 2005, when calling a report via a webform reportViewer control

I've found some very complicated examples of creating your own class with IReportServerCredentials, but I can't seem to get it to work. Is there some simple example available

Marie




Re: Visual Studio Report Controls set credentials for ReportViewer?

Brian Hartman - MSFT

Specifying credentials to the server in the webform control is a little more complicated. The problem is that the webforms control will make server calls asynchronously with the page. So the control either needs the credentials in ASP session or be able to get them when it executes the asynchronous iframe or retrieves report images.. To specify credentials, you have two options:

1. Implement IReportServerCredentials on a serializable object and pass an instance of that object to ReportViewer.ServerReport.ReportServerCredentials.

2. Implement IReportServerConnection and specify the type in the config file (http://msdn2.microsoft.com/en-us/library/ms251661.aspx).

Your implementation of IReportServerCredentials should be nearly trivial. You can pass null for most of the properties, and execute your one line of code for the NetworkCredentials property.





Re: Visual Studio Report Controls set credentials for ReportViewer?

Phil Clewes

This code works for me. Add the class and call it as follows:

ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerCredentials("username", "pwd", "domain");

/// <summary>
/// Local implementation of IReportServerCredentials
/// </summary>
public class ReportServerCredentials : IReportServerCredentials
{
private string _userName;
private string _password;
private string _domain;

public ReportServerCredentials(string userName, string password, string domain)
{
_userName = userName;
_password = password;
_domain = domain;
}

public WindowsIdentity ImpersonationUser
{
get
{
// Use default identity.
return null;
}
}

public ICredentials NetworkCredentials
{
get
{
// Use default identity.
return new NetworkCredential(_userName, _password, _domain);
}
}

public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority)
{
// Do not use forms credentials to authenticate.
authCookie = null;
user = password = authority = null;
return false;
}
}





Re: Visual Studio Report Controls set credentials for ReportViewer?

Marie Ramos

Thanks very much Phil. This is exactly what I've been looking for.

Marie





Re: Visual Studio Report Controls set credentials for ReportViewer?

JeepATLGuy

How would this translate to VB I am really struggling I have reports on a Report Server and am trying to build an webpage with the report viewer to run a report but I need to pass my UserName and Password onto the report server as it is in a shared hosting enviroment....I have been researching and still can't find the right answer.




Re: Visual Studio Report Controls set credentials for ReportViewer?

coderjedi

Here is the VB Code for the class:

Code Snippet

Imports Microsoft.Reporting.WebForms
Imports System.Net

Public Class Class1
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.WebForms.IReportServerCredentials.GetFormsCredentials
authCookie = Nothing
userName = Nothing
password = Nothing
authority = Nothing
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 New NetworkCredential(_username, _password, _domain)
End Get
End Property

End Class






Re: Visual Studio Report Controls set credentials for ReportViewer?

csgear

Hi, Marie:

What's the authentication mode for your application In my case, the above solution only works with <authentication mode= "None" />

Thanks!





Re: Visual Studio Report Controls set credentials for ReportViewer?

qubits

Hi, i don't mean to but in but i think my problem relates to this closely.

I've impemented the above VBcode, and actually i found it on another posting in a different forum. The code is almost identical except for the GetFormsCredentials function:

Here:

Code Snippet

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

authCookie = Nothing

userName = Nothing

password = Nothing

authority = Nothing

Return False

End Function

There:

Code Snippet

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

Return Nothing

End Function

I've tried both but have resulted with the same problem which is an HTTP 404. I don't know why i'm getting this, my server report path is fine, i've checked it many times.

Anyone have any advice