My goal is to display a report from remote ssrs report server. I'm attempting to display a sample report on ASP.NET MVC framework.
N.B I'm able to view the report on the browser with user authentication.
On the runReport.aspx I have the following.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="runReports.aspx.cs" Inherits="WebClient.reports.runReporting" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form runat="server">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<rsweb:ReportViewer ID="MainReportViewer" runat="server" BackColor="White"
Font-Names="Verdana" Font-Size="8pt" InteractiveDeviceInfos=" (Collection)"
ProcessingMode="Remote" ShowBackButton="False" ShowFindControls="False"
ShowPageNavigationControls="False" SizeToReportContent="True"
ToolBarItemBorderColor="White" ToolBarItemHoverBackColor="White"
WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="100%">
<ServerReport ReportServerUrl="" />
</rsweb:ReportViewer>
</form>
</body>
</html>
On the code behind
protected void Page_Load(object sender, EventArgs e) {
MainReportViewer.ProcessingMode = ProcessingMode.Remote;
IReportServerCredentials irsc = new CustomReportCredentials("username", "password", "https://servername.com");
MainReportViewer.ServerReport.ReportServerCredentials = irsc;
MainReportViewer.ServerReport.ReportServerUrl = new Uri("https://servername.com/reports");
MainReportViewer.ServerReport.ReportPath = "/report/Sample_Report_Project" + "/" + "Report_1";
}
On CustomReportCredentials.cs
public class CustomReportCredentials : IReportServerCredentials
{
private string _UserName;
private string _PassWord;
private string _DomainName;
public CustomReportCredentials(string UserName, string PassWord, string DomainName)
{
_UserName = UserName;
_PassWord = PassWord;
_DomainName = DomainName;
}
public System.Security.Principal.WindowsIdentity ImpersonationUser
{
get { return null; }
}
public ICredentials NetworkCredentials
{
get { return new NetworkCredential(_UserName, _PassWord, _DomainName); }
}
public bool GetFormsCredentials(out Cookie authCookie, out string user,
out string password, out string authority)
{
authCookie = null;
user = password = authority = null;
return false;
}
}