1

我有一个 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 中提供的身份验证。我知道有一种方法可以实现自定义身份验证。除此之外,还有什么方法可以单次登录

4

2 回答 2

0

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

}
于 2022-02-27T07:44:56.820 回答
0

我想出了解决方案。要iframeReportViewer.

<%@ 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>;

之后,输入 webform 项目iframe的URL;src例如,

localhost/ReportPage.aspx

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

于 2022-02-25T10:20:45.693 回答