【问题标题】:ReportViewer control using ReportServerCredentials.NetworkCredentials使用 ReportServerCredentials.NetworkCredentials 的 ReportViewer 控件
【发布时间】:2012-03-18 23:32:12
【问题描述】:

我正在使用 ReportViewer 控件从部署在 IIS7 上的 VS2010 ASP.NET MVC 2 Web 应用程序访问 SSRS 2008 报告,设置如下:

  1. 已启用表单身份验证和匿名身份验证
  2. ASP.NET 模拟已禁用
  3. 应用程序池标识配置为使用本地用户帐户,该帐户有权访问应用程序所需的服务器上的特定文件夹
  4. 网络服务器不是域的一部分,但 SSRS 服务器在域中

由于我需要使用单独的凭据来访问 SSRS 报告,因此我已经实现了 IReportServerCredentials,如下所述:

http://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.ireportservercredentials(v=vs.100).aspx

我遇到的问题是它总是转到 IReportServerCredentials.ImpersonationUser 而不是 IReportServerCredentials.NetworkCredentials 我需要它去的地方,因为我正在从 web.config 中检索所需的凭据。

也许我在这里遗漏了一些简单的东西,但我尝试了这些设置的不同组合并且没有运气。任何有关我如何使这项工作的指示将不胜感激!

我的代码:

[Serializable]
public sealed class MyReportServerCredentials : 
    IReportServerCredentials
{
    public WindowsIdentity ImpersonationUser
    {
        get
        {
            // Use the default Windows user.  Credentials will be
            // provided by the NetworkCredentials property.
            return null;
        }
    }

    public ICredentials NetworkCredentials
    {
        get
        {
            // Read the user information from the Web.config file.  
            // By reading the information on demand instead of 
            // storing it, the credentials will not be stored in 
            // session, reducing the vulnerable surface area to the
            // Web.config file, which can be secured with an ACL.

            // User name
            string userName = 
                ConfigurationManager.AppSettings
                    ["MyReportViewerUser"];

            if (string.IsNullOrEmpty(userName))
                throw new Exception(
                    "Missing user name from web.config file");

            // Password
            string password = 
                ConfigurationManager.AppSettings
                    ["MyReportViewerPassword"];

            if (string.IsNullOrEmpty(password))
                throw new Exception(
                    "Missing password from web.config file");

            // Domain
            string domain = 
                ConfigurationManager.AppSettings
                    ["MyReportViewerDomain"];

            if (string.IsNullOrEmpty(domain))
                throw new Exception(
                    "Missing domain from web.config file");

            return new NetworkCredential(userName, password, domain);
        }
    }

    public bool GetFormsCredentials(out Cookie authCookie, 
                out string userName, out string password, 
                out string authority)
    {
        authCookie = null;
        userName = null;
        password = null;
        authority = null;

        // Not using form credentials
        return false;
    }
}


this.MyReportView.ServerReport.ReportServerCredentials = new MyReportServerCredentials();

谢谢

【问题讨论】:

    标签: asp.net-mvc-2 reporting-services reportviewer


    【解决方案1】:

    我在我需要的每个报告页面上都实现了这个相同的类,并且它工作正常。

    检查您的 web.config 文件。

    我有:

    <configuration>
    <system.web>
    <authentication mode="Windows"/>
    </configuration>
    </system.web>
    

    是的。身份验证模式“Windows”。

    但是,我也使用过表单身份验证。

    所以我认为这更多是权限问题。

    查看这篇文章:

    UAC Windows 7 (Proffesional) 64 bit and SSRS 2008 R2 (10.50.1617) 64 bit

    还有这篇文章:

    Reporting Services 2008: asking for username and password

    【讨论】:

    • 感谢 Nathan 的回复和有用的链接。似乎在加载报告时,它首先调用 ImpersonationUser,然后在提供的 ReportServerCredentials 中调用 NetworkCredentials,这是我之前没有意识到的。您链接中的文章有助于更好地理解这一点。它现在按预期工作。
    猜你喜欢
    • 2010-12-20
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多