将凭据从reportviewer传递到报表服务器时未经授权

问题描述 投票:0回答:1

我有以下控制器(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;
        }
    }
}

和以下视图(Index.cshtml):

@using ReportViewerForMvc;

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

我可以在不通过凭据的情况下查看报告(手动通过凭据)。

通过传递的凭据,我收到此错误消息:

'/'应用程序中的服务器错误。

请求失败,HTTP状态为401:未授权。描述:当前执行过程中发生未处理的异常网络请求。请查看堆栈跟踪以获取有关的更多信息错误及其在代码中的起源。

异常详细信息:System.Net.WebException:请求失败,并带有HTTP状态401:未经授权。

源错误:

[未执行的异常是在执行当前的Web请求。有关原产地和位置的信息可以使用下面的异常堆栈跟踪来标识异常。

堆栈跟踪:

[[WebException:请求失败,HTTP状态为401:未经授权。]Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.GetSecureMethods()+192 Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.IsSecureMethod(字符串方法名)+51Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.SetConnectionSSLForMethod(String方法名)+12Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.ProxyMethodInvocation.Execute(RSExecutionConnection连接,ProxyMethod1 initialMethod, ProxyMethod1 retryMethod)+449 Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.LoadReport(String报表,字符串历史记录ID)+180Microsoft.Reporting.WebForms.SoapReportExecutionService.LoadReport(String报告,字符串historyId)+24Microsoft.Reporting.WebForms.ServerReport.EnsureExecutionSession()+70Microsoft.Reporting.WebForms.ServerReport.GetParameters()+54ReportViewerForMvc.ReportViewerExtensions.SetProperties(ServerReportserverReport,ServerReport属性)+60ReportViewerForMvc.ReportViewerExtensions.SetProperties(ReportViewerreportViewer,ReportViewer属性)+154ReportViewerForMvc.ReportViewerWebForm.BuildReportViewer()+67ReportViewerForMvc.ReportViewerWebForm.Page_Load(对象发送者,EventArgs e)+5System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象发送方,EventArgs e)+52 System.Web.UI.Control.OnLoad(EventArgs e)+97System.Web.UI.Control.LoadRecursive()+61System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔值includeStagesAfterAsyncPoint)+693

这是rsreportserver.config的值

<AuthenticationTypes>            
  <RSWindowsNTLM/>
</AuthenticationTypes>

当我单击URL时,在Report Server Configuration Manager下的Web Portal URL中有此错误消息

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.

c# asp.net reporting-services ssrs-2012 reportviewer
1个回答
1
投票

据我所知,您的代码很好。我只是快速按一下boilerplate MVC project来针对我的SSRS实例进行测试,并成功运行了它,而无需更改您的代码。

所以看来问题在于您正在运行的环境:

  1. [Check if you SSRS is configured接受您的特定身份验证请求(默认情况下应随NTLM进行协商,但您没有指定是否仍然适合您)。

  2. ReportViewer控件本身依赖于ASP.NET会话来保持状态,因此check if you need to work around表示。

由于我对您的特定设置了解不多,所以我不能更具体了,但希望它为您提供了两个可供选择的选项。

© www.soinside.com 2019 - 2024. All rights reserved.