0
votes

I have the following controller (ReportsController.cs)

using Microsoft.Reporting.WebForms;
using System;
using System.Configuration;
using System.Web.Mvc;
using System.Net;

namespace ActiveDirectoryAuthentication.Controllers
{
    public class ReportsController : Controller
    {
        // GET: Reports
        public ActionResult Index()
        {
            string ssrsUrl = ConfigurationManager.AppSettings["SSRSReportsUrl"].ToString();
            ReportViewer viewer = new ReportViewer();
            IReportServerCredentials irsc = new CustomReportCredentials("uname", "pwd", "domain");
            viewer.ServerReport.ReportServerCredentials = irsc;
            viewer.ProcessingMode = ProcessingMode.Remote;
            viewer.SizeToReportContent = true;
            viewer.AsyncRendering = true;
            viewer.ServerReport.ReportServerUrl = new Uri(ssrsUrl);
            viewer.ServerReport.ReportPath = "/Temperature_Graphs_Reports/Temperature_Graphs";
            viewer.ServerReport.Refresh();

            ViewBag.ReportViewer = viewer;

            return View();
        }
    }

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

and the following view (Index.cshtml):

@using ReportViewerForMvc;

@if (ViewBag.ReportViewer != null)
{
    @Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)
}

I can view the report without passing credentials (passing them manually).

With passing credentials I have this error message:

Server Error in '/' Application.

The request failed with HTTP status 401: Unauthorized. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The request failed with HTTP status 401: Unauthorized.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[WebException: The request failed with HTTP status 401: Unauthorized.] Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.GetSecureMethods() +192 Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.IsSecureMethod(String methodname) +51
Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.SetConnectionSSLForMethod(String methodname) +12
Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.ProxyMethodInvocation.Execute(RSExecutionConnection connection, ProxyMethod1 initialMethod, ProxyMethod1 retryMethod) +449 Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.LoadReport(String Report, String HistoryID) +180
Microsoft.Reporting.WebForms.SoapReportExecutionService.LoadReport(String report, String historyId) +24
Microsoft.Reporting.WebForms.ServerReport.EnsureExecutionSession() +70 Microsoft.Reporting.WebForms.ServerReport.GetParameters() +54
ReportViewerForMvc.ReportViewerExtensions.SetProperties(ServerReport serverReport, ServerReport properties) +60
ReportViewerForMvc.ReportViewerExtensions.SetProperties(ReportViewer reportViewer, ReportViewer properties) +154
ReportViewerForMvc.ReportViewerWebForm.BuildReportViewer() +67
ReportViewerForMvc.ReportViewerWebForm.Page_Load(Object sender, EventArgs e) +5
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +52 System.Web.UI.Control.OnLoad(EventArgs e) +97
System.Web.UI.Control.LoadRecursive() +61
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +693

This is the value of rsreportserver.config

<AuthenticationTypes>            
  <RSWindowsNTLM/>
</AuthenticationTypes>

In Report Server Configuration Manager under Web Portal URL when I click the URL I have this error message

The service is not available. The report server isn’t configured properly. Contact your system administrator to resolve the issue. System administrators: The report server Web Portal URLs and Web Service URLs don’t match. Use Reporting Services Configuration Manager to configure the URLs and ensure they match.

1
This thread might help you fixing the configuration issuetimur
@timur Thank you. I fixed the configuration. And in the report manager I set logging in through database account on data source and that helped. Your answer and comment was very useful as well.xralf

1 Answers

1
votes

As far as I can tell, your code is fine. I just whipped up a quick boilerplate MVC project to test it against my SSRS instance and had success running it with no change to your code.

So it seems the issue is rather with environment you are running:

  1. Check if you SSRS is configured to accept your specific authentication requests (It should come with NTLM and Negotiate by default, but you did not specify if that is still the case for you).

  2. The ReportViewer control itself relies on ASP.NET session to keep the state, so check if you need to work around that.

Since I don't know much about your specific setup I can't be more specific, but hopefully this gives you a couple of options to explore.