首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ReportViewer控件的ReportServerCredentials.NetworkCredentials

使用ReportViewer控件的ReportServerCredentials.NetworkCredentials
EN

Stack Overflow用户
提问于 2012-03-18 23:32:12
回答 1查看 8.8K关注 0票数 0

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

  1. 启用窗体身份验证和匿名身份验证
  2. 禁用ASP.NET模拟
  3. 应用程序池标识配置为使用对应用程序所需的服务器上的特定文件夹具有访问权限的本地用户帐户。
  4. webserver不是域的一部分,但是SSRS服务器位于域上。

由于我需要使用单独的凭据来访问SSRS报告,所以我实现了IReportServerCredentials,如下所示:

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

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

也许我错过了一些简单的东西,但我尝试了不同的组合这些设置,没有运气。任何关于我如何获得这项工作的建议都将是非常感谢的!

我的代码:

代码语言:javascript
复制
[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();

谢谢

EN

回答 1

Stack Overflow用户

发布于 2012-03-20 06:03:01

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

检查您的web.config文件。

我有:

代码语言:javascript
复制
<configuration>
<system.web>
<authentication mode="Windows"/>
</configuration>
</system.web>

是。身份验证模式"Windows“。

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

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

检查这篇文章:

UAC 7 (Proffesional) 64位和SSRS 2008 R2 (10.50.1617) 64位

也是这个职位:

Reporting 2008:询问用户名和密码

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9763282

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档