Home > C# on .NET > How to publish SSRS report to anonymous web site using ASP.NET (#3/3) – Buiding ASP.NET application

How to publish SSRS report to anonymous web site using ASP.NET (#3/3) – Buiding ASP.NET application

Pre-readings :

How to publish SSRS report to anonymous web site using ASP.NET (#1/3) – Prerequisites
https://fullsocrates.wordpress.com/2016/06/29/how-to-publish-ssrs-report-to-anonymous-web-site-using-asp-net-12-prerequisites/

How to publish SSRS report to anonymous web site using ASP.NET (#2/3) – Buiding SSRS reports
https://fullsocrates.wordpress.com/2016/06/30/how-to-publish-ssrs-report-to-anonymous-web-site-using-asp-net-23-buiding-ssrs-reports/

 

Creating ASP.NET project in Visual Studio


image

In VS (VS2010 for this case), create a new project, and select Visual C# > Web and ‘ASP.NET Empty Web Application’. I named ‘SSRS_WebReport’ for this case.

And then, add a new item (Web Form) in the solution explorer, and name it default.aspx for this case, as shown below,

image

 

I’m going to design ‘default.aspx’ as below, to start this, click ‘default.aspx’, and right-click ‘view designer’ in solution explorer

image

. Type ‘SSRS Web Access Demo’

From toolbox of VS,

. Drag and drop a button control,

. Drag and drop AJAX Extensions>ScriptManager

. Drag and drop HTML>Div under ScriptManager

. Drag and drop Reporting>ReportViewer in the above DIV area (carefully)

image

Double click the above button to add a handler – Button1_Click

Default.aspx has the following source at the moment,

image

 

. Edit title, text, button text as you want

 

To authenticate a user to access a report using ReportViewer control, it’s required to add a class, named ‘CustomReportCredentials’ as below

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;

using Microsoft.Reporting.WebForms;

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;
    }
}

CustomReportCredentials class – reference : http://www.smarterasp.net/support/kb/a1705/how-to-integrate-ssrs-into-asp_net.aspx

In default.aspx.cs, use the above class, and reportviewer control as follows,

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.Reporting.WebForms;

namespace SSRS_WebReport
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            IReportServerCredentials irsc = new CustomReportCredentials("ReportWebUser", "P@ssw0rd", "jchoi02");
            ReportViewer1.ServerReport.ReportServerCredentials = irsc;

            ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
            ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://jchoi02:802/ReportServer");
            ReportViewer1.ServerReport.ReportPath = "/SSRS_WebAccess/UserAgeReport";
            ReportViewer1.SizeToReportContent = true;

            ReportViewer1.ServerReport.Refresh();

        }
    }
}

 

Edit parameters to make this work in your system,

. replace user account, password, and server name at
new CustomReportCredentials("ReportWebUser", "P@ssw0rd", "jchoi02");

. replace ‘Report Server URL’ at
new Uri("http://jchoi02:802/ReportServer");

. repalce Report Path at
ReportViewer1.ServerReport.ReportPath = "/SSRS_WebAccess/UserAgeReport";

If there’s an error when you build this project, you may need to review references as below,

image

 

After building this project, start debugging to check aspx page as follows,

image

In a browser screen, click ‘Show me the report’ then SSRS report will be displayed as above,

 

Deploying ASP.NET appliction on IIS


Let us deploy this project to publish to a ASP.NET web site,

image

 

In VS, click publish (right click on a project name in solution explorer), and I’m going to use ‘File System’ as a publish method, to do XCOPY deployment in IIS

Now, open IIS Manager, and create a new web site, named SSRS_Web

image

You may edit just port number (808 for this case), and path of contents, and leave the rest settings with default values. The path is same with the target location deployed in VS, and avoid to use same port number with other web sites.
And make sure that the above web site allows ‘Anonymous Access’

Note : You might need to change application pool setting to specify  .NET Framework version as shown below picture, this can be done in IIS Manager > Application Pool, and open basic settings of an application pool . 
Just make sure that the version needs to be same with .NET Framework verion of your ASP.NET project. The installed .NET Framework version and default verion of application pool depend on your system

image

 

After all, access our ASP.NET/C# applciation in the web site with a URL (http://jchoi02:808/),  the SSRS report can be displayed in a web browser,

image,

 

In summary,


To create a simple report from SQL Server, SSRS provides a way to build a report using VS and data access via dataset.

Publishing SSRS report in IIS web site for anonymous users, is one of options to use a simple and quick BI for a company, or teams. SQL/SSRS/IIS and ASP.NET support many of BI requirements, and easy access via web.

FYI, to provide users with complex, decent, and gorgeous business reports, probably, SSRS is not the solution for you, do not go through painful efforts to build them. With SSRS, only simple reports are recommended for your better work and life.

 

Hope this helps

 

Related reference articles

How to publish SSRS report to anonymous web site using ASP.NET (#1/3) – Prerequisites
https://fullsocrates.wordpress.com/2016/06/29/how-to-publish-ssrs-report-to-anonymous-web-site-using-asp-net-12-prerequisites/

How to publish SSRS report to anonymous web site using ASP.NET (#2/3) – Buiding SSRS reports
https://fullsocrates.wordpress.com/2016/06/30/how-to-publish-ssrs-report-to-anonymous-web-site-using-asp-net-23-buiding-ssrs-reports/

Advertisements
Categories: C# on .NET

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: