【问题标题】:Reporting Services prompts for CredentialsReporting Services 提示凭据
【发布时间】:2020-08-11 07:30:56
【问题描述】:

我有一个 iframe,我将通过它调用报告服务

<iframe src="@(ViewBag.ReportUrl)" id="ifReport" scrolling="yes" height="500" width="100%"></iframe>

每次我尝试调用此服务时,它都会要求提供凭据

有什么办法可以避免这个提示。我的 Web 应用程序使用 Active Directory 凭据进行登录,因此这里使用相同的凭据。我可以在调用此服务时使用该凭据以避免提示吗?我已经提到了https://stackoverflow.com/a/12166240/10325225。但这个答案让我无处可去

<AuthenticationTypes>
            <RSWindowsNTLM/>
        </AuthenticationTypes>
        <RSWindowsExtendedProtectionLevel>Off</RSWindowsExtendedProtectionLevel>
        <RSWindowsExtendedProtectionScenario>Proxy</RSWindowsExtendedProtectionScenario>
        <EnableAuthPersistence>true</EnableAuthPersistence>
    </Authentication>

这些是 RSReportServer.config 中提供的身份验证。我知道有一种方法可以实现自定义身份验证。除此之外还有什么方法可以单次登录

【问题讨论】:

    标签: asp.net-mvc reporting-services reporting-services-2012


    【解决方案1】:

    我想出了解决办法。要查看iframe 中的报告,您必须首先创建一个小型 ASP.NET Web 窗体项目,其中包含一个内部带有ReportViewer 控件的页面:

    <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
    
    <form id="form1" runat="server">
           <asp:ScriptManager runat="server"></asp:ScriptManager>
           <rsweb:ReportViewer ID="ReportViewer1" runat="server" >
           </rsweb:ReportViewer>
     </form>
    
    ReportViewer1.ProcessingMode = ProcessingMode.Remote;
    CustomReportCredentials irsc = new CustomReportCredentials(userName,password, domain); // if you dont have a domain enter computer name
    ReportViewer1.ServerReport.ReportServerCredentials = irsc;
    ReportViewer1.ServerReport.ReportServerUrl = host/reportServer not portal;
    ReportViewer1.ServerReport.ReportPath = important! <report path with folder that contains report.rdl>;
    

    然后,将iframesrc URL 放入webform 项目;例如,

    localhost/ReportPage.aspx
    

    如果您在 Google 上搜索,您可以找到 class CustomReportCredentials :IReportServerCredentials 的示例。

    【讨论】:

    • 您能否链接到此类实现的示例,而不仅仅是引导读者在 Google 上搜索?
    【解决方案2】:

    在 ReportPage.aspx 中

    <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
    
      <form id="CommonReport" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="100%" Width="100%">
        </rsweb:ReportViewer>
    </form>  
    

    在 ReportPage.aspx.cs 中

    namespace ReportWebForm
    {
         public partial class ReportPage:SystemWeb.Ui.Page
             {
                 if(!IsPostBack)
                 {
                   CustomReportCredentials  irsc = new CustomReportCredentials(userName, password,domain) //if you dont have domain enter computer name
                 ReportViewer1.ProcessingMode = ProcessingMode.Remote;
                 ReportViewer1.ServerReport.ReportServerCredentials = irsc;
             ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://<ssrs ip>/ReportServer"); 
                 ReportViewer1.ServerReport.ReportPath = "ReportFolder/Report1";
                 }
             }
    
          [Serializable]
          public class CustomReportCredentials : IReportServerCredentials
            {
                private string reportServerUserName;
                private string reportServerPassword;
                private string reportServerDomain;
        
                public CustomReportCredentials(string userName, string password, string domain)
                {
                    reportServerUserName = userName;
                    reportServerPassword = password;
                    reportServerDomain = domain;
                }
                public WindowsIdentity ImpersonationUser
                {
                    get
                    {
                        // Use default identity.
                        return null;
                    }
                }
        
                public ICredentials NetworkCredentials
                {
                    get
                    {
                        // Use default identity.
                        return new NetworkCredential(reportServerUserName, reportServerPassword, reportServerDomain);
                    }
                }
                public void New(string userName, string password, string domain)
                {
                    reportServerUserName = userName;
                    reportServerPassword = password;
                    reportServerDomain = domain;
                }
        
                public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority)
                {
                    // Do not use forms credentials to authenticate.
                    authCookie = null;
                    user = null;
                    password = null;
                    authority = null;
        
                    return false;
                }
            }
    
    }
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    相关资源
    最近更新 更多