实现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,到此就可以实现了。
分享到:
相关推荐
Pro SQL Server 2008 Reporting Services.pdf 英文版
SQL Server 2008 Reporting Services 入门教程(E)和源代码
英文版一步一步学习sql 2008 报表服务
Microsoft SQL Server 2008 Reporting Services Step By Step.part4
Microsoft SQL Server 2008 Reporting Services Step By Step.part1
Microsoft SQL Server 2008 Reporting Services Step By Step.part2
Microsoft-SQL Server 2008 Reporting Services Step by Step(2009) 随书光盘 案例数据库文件及补充阅读
SQL Server 2008 Reporting Services 报表服务中的编程
Microsoft-SQL Server 2008 Reporting Services Step by Step(2009).pdf, 学习2008 报表服务的好书
Packt.Publishing.Learning.SQL.Server.2008.Reporting.Services.Mar.2009
Microsoft SQL Server 2005 Reporting Services (SQL Server Series)
Professional Microsoft SQL Server 2016 Reporting Services and Mobile Reports provides a comprehensive lesson in business intelligence (BI), operational reporting and Reporting Services architecture ...
Pro SQL Server 2008 Reporting Services ,数据库高级教程 PDF格式 英文版
A step-by-step guide to getting the most of Microsoft SQL Server Reporting Services 2008 Microsoft SQL Server Reporting Services 2008 is the third generation Microsoft reporting software that is more...
SQL Server 2008 Reporting Services(SSRS)动手实验操作教程
[Microsoft SQL Server 2005 Reporting Services专家教程]源文件.rar
Applied Microsoft SQL Server 2008 Reporting Services.part2
Applied Microsoft SQL Server 2008 Reporting Services.part1
Ebook - SQL Server 2008 Reporting Services (Part 1/3)