`
zrj_software
  • 浏览: 201506 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

SQL Server 2008 Reporting Services实现匿名访问报表

    博客分类:
  • C#
阅读更多

实现SQL Server 2008 Reporting Services匿名访问报表有两种方法。

一、通过修改SQL Server 2008的配置文件,去掉Windows的验证。

1.首先我们找到SQL安装目录下的两个Web.config配置文件,默认安装目录分别是(C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer和C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportManager),然后,找到两个配置文件中的 

<authentication mode="windows"/> <identity impersonate="true"/> 


将其改为:

<authentication mode="None"/> <identity impersonate="false" />

 

 

2.找到(C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer)目录下的rsreportserver.config文件,找到配置文件中的

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


将其改为: 

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


然后找到配置文件中的 

<Security>
    <Extension Name="Windows" Type="Microsoft.ReportingServices.Authorization.WindowsAuthorization, Microsoft.ReportingServices.Authorization"/>
</Security>
<Authentication> 
    <Extension Name="Windows" Type="Microsoft.ReportingServices.Authentication.WindowsAuthentication,Microsoft.ReportingServices.Authorization"/> 
</Authentication> 

 

将其改为: 

<Security> 
    <Extension Name="None" Type="Microsoft.Samples.ReportingServices.AnonymousSecurity.Authorization,Microsoft.Samples.ReportingServices.AnonymousSecurity"/> </Security>
<Authentication>
     <Extension Name="None" Type="Microsoft.Samples.ReportingServices.AnonymousSecurity.AuthenticationExtension,Microsoft.Samples.ReportingServices.AnonymousSecurity"/> 
</Authentication>

 

这里需要引用一个DLL文件,就是Microsoft.Samples.ReportingSerices.
 
3.将dll放入到目录C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer\bin,接下来继续修改我们的配置文件,在(C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer)目录下,找到rssrvpolicy.config找到

<CodeGroup class="FirstMatchCodeGroup" version="1" PermissionSetName="Nothing">
<IMembershipCondition class="AllMembershipCondition" version="1" /> 

 

在其下边追加如下节点(红色部分,按照你的实际路径而定)

<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="Private_assembly" Description="This code grou p grants custom code full trust."> 
<IMembershipCondition class="UrlMembershipCondition" version="1" Url="C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER2008\Reporting Services\ReportServer\bin\Microsoft.Samples.ReportingServices.AnonymousSecurity.dll"/> 
</CodeGroup> 

 

到此为止,我们匿名登录的方式,配置工作就完成了。
 
二、利用接口IReportServerCredentials 和IReportServerConnection将Windows的用户名和密码传进去以实现匿名访问报表。
1.利用IReportServerCredentials 接口
接口定义为:

using System;
using Microsoft.Reporting.WebForms;
using System.Net;
using System.Security.Principal;
using System.Configuration;

namespace SqlReport
{
    [Serializable]
    class MyConfigFileCredentials : IReportServerCredentials
    {
        public MyConfigFileCredentials()
        {
        }

        public WindowsIdentity ImpersonationUser
        {
            get
            {
                return null;
            }
        }

        public ICredentials NetworkCredentials
        {
            get
            {
                return new NetworkCredential("Administrator","123456");//windows的用户名和密码
            }
        }

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

 

 

在调用报表的代码如下:
using System;
using System.Web;
using Microsoft.Reporting.WebForms;


namespace SqlReport
{
    public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if ((!IsPostBack) && Request.QueryString.Count > 0)
            {
                string reportPath = Request.QueryString[0];
                this.ReportLabel.Text = Request.QueryString[0];
             
                this.ReportViewer3.ProcessingMode = ProcessingMode.Remote;
                MyConfigFileCredentials rsc = new MyConfigFileCredentials();

                this.ReportViewer3.ServerReport.ReportServerCredentials = rsc;
                this.ReportViewer3.ServerReport.ReportPath = reportPath;
                this.ReportViewer3.ServerReport.ReportServerUrl = new Uri((Properties.Settings.Default.MyReportServerUrl));
                this.ReportViewer3.ServerReport.Refresh();
            }
        }
    }
}

  

 

2.利用IReportServerConnection接口,接口定义:

using System;
using System.Collections.Generic;
using System.Net;
using System.Security.Principal;
using Microsoft.Reporting.WebForms;

namespace SqlReport
{
    [Serializable]
    public class MyReportServerConnection : IReportServerConnection
    {
        public Uri ReportServerUrl
        {
            get
            {
                string url = Properties.Settings.Default.MyReportServerUrl;
                if (string.IsNullOrEmpty(url))
                    throw new Exception("Missing url from the Web.config file");
                return new Uri(url);
            }
        }
        public int Timeout
        {
            // set timeout to 60 seconds
            get { return 60000; }
        }

        public IEnumerable<Cookie> Cookies
        {
            // No custom cookies
            get { return null; }
        }
        public IEnumerable<string> Headers
        {
            // No custom headers
            get { return null; }
        }

        public MyReportServerConnection()
        {
        }


        public WindowsIdentity ImpersonationUser
        {
            get { return null; }
        }

        public ICredentials NetworkCredentials
        {
            get
            {
                //this will force the use of impersonation, 
                // otherwise, remove the return null and 
                // implement the other app settings to specify the credential details
                // return null;
                string userName = Properties.Settings.Default.myReportViewerUser;
                if (string.IsNullOrEmpty(userName))
                    throw new Exception("Missing user name from Web.config file");
                string password = Properties.Settings.Default.MyReportViewerPassword;
                if (string.IsNullOrEmpty(password))
                    throw new Exception("Missing password from Web.config file");
                string domain = Properties.Settings.Default.MyReportViewerDomain;
                if (string.IsNullOrEmpty(domain))
                    throw new Exception("Missing domain from Web.config file");
                return new NetworkCredential(userName, password, domain);
                //return new NetworkCredential(userName, password);
            }
        }

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

 

 在调用报表的代码如下:

using System;
using System.Web;
using Microsoft.Reporting.WebForms;


namespace SqlReport
{
    public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if ((!IsPostBack) && Request.QueryString.Count > 0)
            {
                string reportPath = Request.QueryString[0];
                this.ReportLabel.Text = Request.QueryString[0];
              
                this.ReportViewer3.ProcessingMode = ProcessingMode.Remote;
                MyReportServerConnection rsc = new MyReportServerConnection();

                this.ReportViewer3.ServerReport.ReportServerCredentials = rsc;
                this.ReportViewer3.ServerReport.ReportPath = reportPath;
                this.ReportViewer3.ServerReport.ReportServerUrl = new Uri((Properties.Settings.Default.MyReportServerUrl));
                this.ReportViewer3.ServerReport.Refresh();
            }
        }
    }
}

  

 

 

ok,到此就可以实现了。

分享到:
评论

相关推荐

    Reporting Services发布的报表允许匿名访问

    这些步骤包括在Reporting Services站点设置匿名用户角色、在SQL Server中为匿名用户配置登录及权限、以及在IIS中开启匿名访问等功能。这些操作有助于实现更灵活的报表发布方式,使得非认证用户也能访问某些公开报表...

    匿名访问Reporting Service 2008

    6. **使用示例代码**: `Microsoft.Samples.ReportingServices.AnonymousSecurity.dll` 文件可能是一个示例库,提供了实现匿名访问的代码示例。开发者可以参考这个库来了解如何编程式地处理Reporting Services的匿名...

    Reporting Service for SQL 2008匿名访问报表的方法

    在SQL Server 2008中的Reporting Services,允许匿名访问报表是实现无认证用户查看报告的一种方式。以下是如何设置Reporting Service for SQL 2008以支持匿名访问报表的详细步骤: 1. **编译AnonymousSecurity组件*...

    SQL Server 2008+ Reporting Services (SSRS)使用USER登录问题

    网上有关于“SQL Server 2008 Reporting Services匿名访问”的教程,通过修改Reporting Services下的配置文件来实现,我对着着教程做了一遍,没有成功。 突然想到,我只是让有权限的USER账号能访问就行,没必要实现...

    SQL SERVER 2008 R2 报表服务器匿名访问dll文件

    Microsoft.Samples.ReportingServices.AnonymousSecurity.dll文件。 使用方法请参考: http://blog.csdn.net/cendywang/article/details/9194087#comments

    SQL 2008 匿名访问Report Server

    实现SQL 2008 Report Server的匿名访问主要涉及以下几个步骤: 1. **配置IIS**:Report Server是通过Internet Information Services (IIS) 提供Web服务的,因此我们需要在IIS中启用匿名身份验证。打开IIS管理器,...

    AnonymousSecurity.dll文件和配置文档.rar

    以下是关于SQL Server 2008 Reporting Services匿名访问配置的相关知识点: 1. **启用IIS匿名身份验证**:在配置报表服务的匿名访问时,首先需要在IIS(Internet Information Services)中启用匿名身份验证。这通常...

    SQLServer安全及性能优化

    - **SQL Server Reporting Services (SSRS)**:报表服务。 - **SQL Server Integration Services (SSIS)**:数据集成服务。 - **SQL Server 代理**:用于调度作业。 - **SQL Full-text Filter Daemon Launcher**...

    reporting service的部署

    为了确保 Reporting Services 可以被正常访问,首先需要在 IIS 和 SQL Server 2005 中设置,让 Reporting Services 发布的 Web 报表允许匿名访问。具体步骤如下: - 在 IIS 中,选择允许匿名访问的选项(即 IUSR_**...

    企业人事管理系统(C#2.0+SQL Server 2005)

    这些可以通过SQL Server Reporting Services或 Crystal Reports 实现,帮助管理层做出决策。 9. **安装部署**: 完成开发后,需要打包成安装程序,确保在目标环境中能顺利安装并运行。部署过程要考虑配置文件、...

    OA办公系统源码 asp.net 2.0(c#)+SQLServer2005

    9. 报表和统计:系统可能集成了报表生成和数据分析功能,例如使用Crystal Reports或SSRS(SQL Server Reporting Services),帮助管理层获取业务指标和决策依据。 10. 移动设备支持:随着移动办公的需求增加,OA...

    商品进销存报表系统(带完善的系统说明书)

    同时,SQL Server 2005的Reporting Services提供了灵活的报表设计工具,与C#结合可以实现高效的数据可视化。 三、进销存核心功能 1. **进货管理**:系统记录每笔进货的详细信息,包括商品名称、数量、单价、供应商...

    windowsXP下IIS安装文件

    1. **Reporting Services**:SQL Server Reporting Services 是一个用于生成、管理和分发报表的服务,它依赖于IIS来提供Web服务接口,使得用户可以通过浏览器查看报表。 2. **Analysis Services**:SQL Server ...

    XP中安装IIS

    - ** Reporting Services**:SQL Server 2005的Reporting Services需要IIS来发布报表,用户可以通过Web浏览器访问报表。 - **Analysis Services**:IIS用于提供OLAP(在线分析处理)的Web接口,使得用户可以通过...

    ASP.NET3.5完全自学手册——编程技术文档1

    3. **SSRS(SQL Server Reporting Services)**:SSRS提供了一个企业级的报表平台,可以创建丰富的交互式报表,并能够分发到多种格式。 4. **SSAS(SQL Server Analysis Services)**:SSAS提供了多维数据处理和...

    SharePoint Server2007宝典.part02

    22.3.2 启用匿名访问 502 22.3.3 创建专业的Internet存在 503 22.3.4 创建全局导航 505 22.3.5 创建“新闻速递”发布流程 507 22.3.6 配置新闻速递存档 510 22.3.7 配置bug跟踪指标 512 22.3.8 配置技术文章工作流...

    C#2005人事工资管理系统

    7. **报表生成**:可能使用Crystal Reports或内置的Reporting Services创建工资单、考勤统计等报表。 8. **性能优化**:考虑数据库索引设置,避免全表扫描,优化查询性能。 9. **版本控制**:通过版本控制系统(如...

    考务信息管理系统(ASP.net)

    其内置的 Reporting Services 和 Analysis Services 还能帮助管理者生成报表和进行数据分析,为决策提供有力支持。 考务信息管理系统的核心功能包括: 1. 考生管理:录入、修改、删除考生基本信息,如姓名、学号、...

    银行存储数据库管理系统

    这可以通过报表工具如Crystal Reports或SQL Server Reporting Services实现。同时,日志记录对于跟踪系统行为和故障排查也非常重要。 5. 安全性:银行系统对安全性有极高要求,包括数据加密、权限管理、防火墙等。...

Global site tag (gtag.js) - Google Analytics