最近开发报表,需要ASP.NET访问报表服务器上的相应的报表服务。但是发现,从ASP.NET页面上跳到报表服务器时,会弹出对话框,要求输入报表服务器的用户名和密码才能够登陆,这就造成了如果用户不知道相关账户的情况下无法访问报表服务器的情况。
于是Google之,发现原来这个问题只有在SQL SERVER 2008开始存在,而R2的话会更新一点东西。在过去SQL SERVER 2005可以通过IIS的用户权限设置来满足相关的需求。但是SQL SERVER 2008已经脱离IIS而独立存在,因此过去SQL 2005的方法不再适用。
研究了两天,发现修改配置文件,增加.dll的方法最终使得我SQL SERVER 2008 R2服务器上的报表服务实现了匿名访问,达到了要求。在这里记录一下,也许以后还用得上。
1. 修改C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer下rsreportserver.config文件为如下:
<Authentication>
<AuthenticationTypes>
<Custom/>
</AuthenticationTypes>
<RSWindowsExtendedProtectionLevel>Off</RSWindowsExtendedProtectionLevel>
<RSWindowsExtendedProtectionScenario>Proxy</RSWindowsExtendedProtectionScenario>
<EnableAuthPersistence>true</EnableAuthPersistence>
</Authentication>
2.将 report server和report manager文件夹内的web.config,修改为以下内容。
<authentication mode="None" />
<identity impersonate="false"/>
3.将Microsoft.Samples.ReportingServices.AnonymousSecurity.dll放到C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer\bin里面。
这里Microsoft.Samples.ReportingServices.AnonymousSecurity.dll其实是一个需要编译的C#代码,但我自己使用VS2005和VS2008编译的都会出现以下错误:
ERROR: Exception caught instantiating None report server extension: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Samples.ReportingServices.AnonymousSecurity' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
查找了一下,是编译器链接的.NET版本导致的,需要最好是.NET2.0来编译会成功。因此最后我网上找了一个,运行成功。我在这里本地提供下下载:
http://download.csdn.net/detail/cendywang/6509299
4.修改步骤1中rsreportserver.config为以下内容:
<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>
5.在rssrvpolicy.config中,在以下代码后面
<CodeGroup
class="FirstMatchCodeGroup"
version="1"
PermissionSetName="Execution"
Description="This code group grants MyComputer code Execution permission. ">
<IMembershipCondition
class="ZoneMembershipCondition"
version="1"
Zone="MyComputer" />
增加以下代码:
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Private_assembly"
Description="This code group grants custom code full trust. ">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer\bin\Microsoft.Samples.ReportingServices.AnonymousSecurity.dll"
/>
</CodeGroup>
完成后,重启一下报表服务器,匿名访问就可以了。