【发布时间】:2020-01-14 13:35:47
【问题描述】:
我有以下控制器(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:未经授权。
来源错误:
在执行过程中产生了一个未处理的异常 当前的网络请求。有关原产地和位置的信息 可以使用下面的异常堆栈跟踪来识别异常。
堆栈跟踪:
[WebException:请求失败,HTTP 状态 401:未授权。] Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.GetSecureMethods() +192 Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.IsSecureMethod(字符串 方法名)+51
Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.SetConnectionSSLForMethod(字符串 方法名)+12
Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.ProxyMethodInvocation.Execute(RSExecutionConnection 连接,ProxyMethod1 initialMethod, ProxyMethod1 retryMethod) +449 Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.LoadReport(字符串 报告,字符串 HistoryID) +180
Microsoft.Reporting.WebForms.SoapReportExecutionService.LoadReport(字符串 报告,字符串 historyId) +24
Microsoft.Reporting.WebForms.ServerReport.EnsureExecutionSession() +70 Microsoft.Reporting.WebForms.ServerReport.GetParameters() +54
ReportViewerForMvc.ReportViewerExtensions.SetProperties(ServerReport serverReport、ServerReport 属性)+60
ReportViewerForMvc.ReportViewerExtensions.SetProperties(ReportViewer reportViewer、ReportViewer 属性)+154
ReportViewerForMvc.ReportViewerWebForm.BuildReportViewer() +67
ReportViewerForMvc.ReportViewerWebForm.Page_Load(对象发送者, 事件参数 e) +5
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象发送者, EventArgs e) +52 System.Web.UI.Control.OnLoad(EventArgs e) +97
System.Web.UI.Control.LoadRecursive() +61
System.Web.UI.Page.ProcessRequestMain(布尔值 includeStagesBeforeAsyncPoint,布尔型 includeStagesAfterAsyncPoint) +693
这是rsreportserver.config的值
<AuthenticationTypes>
<RSWindowsNTLM/>
</AuthenticationTypes>
在Web Portal URL 下的Report Server Configuration Manager 中,当我单击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.
【问题讨论】:
-
This thread 可能会帮助您解决配置问题
-
@timur 谢谢。我修复了配置。在报告管理器中,我设置了通过数据源上的数据库帐户登录,这很有帮助。您的回答和评论也非常有用。
标签: c# asp.net reporting-services ssrs-2012 reportviewer