Monday, March 19, 2012

Logon failed. (rsLogonFailed)

Hi,

I am writing a web application in c# that is attempting to get the parameters from a report on a Reporting Services 2005 server.

I am using the following code:

SQLReportViewer.ServerReport.ReportServerCredentials = new
ReportCredentials(UserName, UserPassword, UserDomain);
SQLReportViewer.ServerReport.ReportPath = Rpt.FileName;
SQLReportViewer.ServerReport.ReportServerUrl = new Uri(ServerUrl);

Parameters = SQLReportViewer.ServerReport.GetParameters();

The Getparameters Line causes the following exception:

Microsoft.Reporting.WebForms.ReportServerException was unhandled by user code
Message="Logon failed. (rsLogonFailed)"
Source="Microsoft.ReportViewer.WebForms"
ErrorCode="rsLogonFailed"
StackTrace:
at Microsoft.Reporting.WebForms.ServerReport.get_Service()
at Microsoft.Reporting.WebForms.ServerReport.GetExecutionInfo()
at Microsoft.Reporting.WebForms.ServerReport.GetParameters()

The UserName, UserPassword and UserDomain variables are all populated with correct data, as is Rpt.FileName.
The ReportCredentials class is a very simple implementation of the ICredentials interface - Code shown here:

-->

public class ReportCredentials : IReportServerCredentials
{
protected string _UserName, _Password, _Domain;

public ReportCredentials(string UserName, string Password, string Domain)
{
_UserName = UserName;
_Password = Password;
_Domain = Domain;
}

//*****************************************************************

public bool GetFormsCredentials (out System.Net.Cookie AuthCookie, out string UserName, out string Password, out string Authority)
{
UserName = _UserName;
Password = _Password;
Authority = _Domain;
AuthCookie = null;
return (true);
}

//*****************************************************************

public System.Security.Principal.WindowsIdentity ImpersonationUser
{
get { return (null); }
}

//*****************************************************************

public ICredentials NetworkCredentials
{
get{ return (new NetworkCredential(_UserName, _Password, _Domain)); }
}

<--

I can use the same credentials to retrieve a list of reports from the report server (the report I am trying to access is in that list) and to log on directly by going to the URL of Reporting Services.

This is made more frustrating by the complete lack of detail in the error message, as it does not say why the logon failed, or give me a single clue about what is going on.

Has anyone seen this before and can tell me how to fix it, or is there something stupid in my code?

Thankyou.

Paul

Does the same thing happen when you do this:

Code Snippet

CredentialCache cc = new CredentialCache();

cc.Add(new Uri(Settings.Default.ReportServerEndPoint),"Basic", new NetworkCredential("uid", "pwd"));

reportViewer.ServerReport.ReportServerCredentials.NetworkCredentials = cc;

|||Hi,

ReportServerCredentials.NetworkCredentials is read only, and so cannot be assigned to.

Thankyou.

|||

You are right of course. Unline the WinForms version, the ASP.NET version of ReportViewer has NetworkCredentials read-only. Upon a second look, I don't see your code implementing IReportServerCredentials.GetBasicCredentials.

Code Snippet

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Reporting.WinForms;
using System.Security.Principal;


public class ReportViewerCredentials : IReportServerCredentials
{

public ReportViewerCredentials()
{
}

public ReportViewerCredentials(string username)
{
this.Username = username;
}


public ReportViewerCredentials(string username, string password)
{
this.Username = username;
this.Password = password;
}


public ReportViewerCredentials(string username, string password, string domain)
{
this.Username = username;
this.Password = password;
this.Domain = domain;
}


public string Username
{
get
{
return this.username;
}
set
{
string username = value;
if (username.Contains("\\"))
{
this.domain = username.Substring(0, username.IndexOf("\\"));
this.username = username.Substring(username.IndexOf("\\") + 1);
}
else
{
this.username = username;
}
}
}
private string username;

public string Password
{
get
{
return this.password;
}
set
{
this.password = value;
}
}
private string password;


public string Domain
{
get
{
return this.domain;
}
set
{
this.domain = value;
}
}
private string domain;


#region IReportServerCredentials Members

public bool GetBasicCredentials(out string basicUser, out string basicPassword, out string basicDomain)
{
basicUser = username;
basicPassword = password;
basicDomain = domain;
return username != null && password != null && domain != null;
}

public bool GetFormsCredentials(out string formsUser, out string formsPassword, out string formsAuthority)
{
formsUser = username;
formsPassword = password;
formsAuthority = domain;
return username != null && password != null && domain != null;

}

public WindowsIdentity ImpersonationUser
{
get
{
return null;
}
}

#endregion
}

|||Hi,

After much messing about and testing, I finally tracked it down to a problem in the GetformsCredentials function in my Credentials class.

By changing it to the following, everything works.

public bool GetFormsCredentials (out System.Net.Cookie AuthCookie, out string UserName, out string Password, out string Authority)
{
UserName = null;
Password = null;
Authority = null;
AuthCookie = null;

return (false);
}

Thanks

Paul

No comments:

Post a Comment