一、通过修改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)
或者(C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer和C:\Program Files\Microsoft SQL Server\MSRS10_50.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]
internal class MyConfigFileCredentials : IReportServerCredentials
{
public MyConfigFileCredentials()
{
} public WindowsIdentity ImpersonationUser
{
get { return null; }
} public ICredentials NetworkCredentials
{
get
{
return new NetworkCredential("Administrator", ""); //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 > )
{
string reportPath = Request.QueryString[];
this.ReportLabel.Text = Request.QueryString[]; 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 ; }
} 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 > )
{
string reportPath = Request.QueryString[];
this.ReportLabel.Text = Request.QueryString[]; 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完成啦。

实现SQL Server 2008 Reporting Services匿名访问报表有两种方法的更多相关文章

  1. Display Database Image using MS SQL Server 2008 Reporting Services

    原文 Display Database Image using MS SQL Server 2008 Reporting Services With the new release of MS SQL ...

  2. SQL SERVER 2008 Reporting Services 的一些小问题集合

    实验环境:服务器  Windows Server  2008 R2 Standard 64bit                   数据库  SQL SERVER 2008 R2 Standard ...

  3. [翻译]初识SQL Server 2005 Reporting Services Part 1

    原文:[翻译]初识SQL Server 2005 Reporting Services Part 1 构建和部署基本报表 如果曾经存在一项工作使得“真正的”开发者给他的上司泡蘑菇,那就是构建报表.毕竟 ...

  4. [翻译]初识SQL Server 2005 Reporting Services Part 3

    原文:[翻译]初识SQL Server 2005 Reporting Services Part 3 这是关于SSRS文章中四部分的第三部分.Part 1提供了一个创建基本报表的递阶教程.Part 2 ...

  5. [翻译]初识SQL Server 2005 Reporting Services Part 4

    原文:[翻译]初识SQL Server 2005 Reporting Services Part 4 这一篇是关于SQL Server 2005 Reporting Services四篇文章中最后一篇 ...

  6. [翻译]初识SQL Server 2005 Reporting Services Part 2

    原文:[翻译]初识SQL Server 2005 Reporting Services Part 2 在Part 1文章中我们对SQL Server Reporting Services 2005(S ...

  7. SQL Server 2008 R2 根据.asmx访问WebService

    .asmx 都是.Net 同系列,所以学习的时候会比较简单. 方法一: 步骤1.在浏览器打开.asmx地址可以到方法列表, 步骤2.点进方法列表会有SOAP调用的案例, 步骤3.SQL Server ...

  8. [转]Using the Microsoft Connector for Oracle by Attunity with SQL Server 2008 Integration Services

    本文转自:http://technet.microsoft.com/en-us/library/ee470675(v=sql.100).aspx SQL Server Technical Articl ...

  9. SQL Server 2008管理工具出现 远程过程调用失败0x800706be解决方法

    解决方法 出现此问题是因为在安装 Visual Studio 2012(VS2012) 时,会自动安装 "Microsoft SQL Server 2012 Express LocalDB& ...

随机推荐

  1. ios 写项目的时候遇到的问题及解决方案(3)

    22.看了苹果的文档,里面有这一句话:All launch images must be PNG files and must reside in the top level of your appl ...

  2. Linux的Service/Daemon你真的懂了吗?

    一 service与一般的程序的区别 service(也称为daemon)表示后台运行的程序,一般随系统的启动自动地启动且在用户logoff后仍然能够继续运行.该daemon进程一般在启动后需要与父进 ...

  3. day1作业--三级菜单

    作业概述: 写一个三级菜单 实现如下功能: (1)可依次选择进入各子菜单 (2)在每一级按“b”都可以返回上一级,按“q"都可以退出 流程图: readme: 简介: three_menu. ...

  4. 【学】jQuery的源码思路4——增加一些功能

    本文说一些简单的jQuery实现原理 eq() get() hide() show() index() find() //返回找到的一组元素中的第n个 zQuery.prototype.eq=func ...

  5. Spark Job的提交与task本地化分析(源码阅读八)

    我们又都知道,Spark中任务的处理也要考虑数据的本地性(locality),Spark目前支持PROCESS_LOCAL(本地进程).NODE_LOCAL(本地节点).NODE_PREF.RACK_ ...

  6. 基础14_转义字符和特殊字符ASCII

    一.摘要 PSQL转义字符 二.PLSQL转义字符 PLSQL对应的字符和序号关系 二.PLSQL特殊字符 PLSQL对应的字符和序号关系 1. 转义字符为' '; )||'%'; --A&B ...

  7. 独自handle一个数据库大程有感

    这学期数据库课程,最后的大程是写一个MiniSQL的数据库实现,要求很简单,建删表,建删单值索引,支持主键和unique定义,支持最简单的select,只要支持3个类型:int,float,char( ...

  8. [Linux编程] module_param()函数学习笔记

    在读TCP cubic源码中,遇到了module_param(),网上查到的资料如下: 在用户态下编程可以通过main()来传递命令行参数,而编写一个内核模块则可通过module_param()来传递 ...

  9. C#:String.Format数字格式化输出 {0:N2} {0:D2} {0:C2}等等

    int a = 12345678; //格式为sring输出//   Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); / ...

  10. [转]理解HTTP幂等性

    基于HTTP协议的Web API是时下最为流行的一种分布式服务提供方式.无论是在大型互联网应用还是企业级架构中,我们都见到了越来越多的SOA或RESTful的Web API.为什么Web API如此流 ...