2011-12-12 59 views
2

我试图从写在报表的自定义代码中的函数访问REST服务。我不想将该代码移入单独的程序集中,因此问题出在自定义代码的周围,请不要发送给定制程序集。SSRS - 自定义代码

下面的代码:

Public Shared Function GetData(ByVal id As String) As String 
    Dim strURL As String = ("http://..." & id) 
    Dim webRequest As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(strURL), System.Net.HttpWebRequest) 
     webRequest.Method = "Get" 
     Dim webResponse As System.Net.HttpWebResponse = DirectCast(webRequest.GetResponse, System.Net.HttpWebResponse) 
     Dim rdr As New System.IO.StreamReader(webResponse.GetResponseStream) 
     Return rdr.ReadToEnd 
End Function 

当我使用它,我收到错误消息:

System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. 
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
at System.Security.CodeAccessPermission.Demand() 
at System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint) 
at System.Net.HttpRequestCreator.Create(Uri Uri) 
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase) 
at System.Net.WebRequest.Create(String requestUriString) 
at ReportExprHostImpl.CustomCodeProxy.GetData(String what, String id, String defaultValue) 
The action that failed was: 
Demand 
The type of the first permission that failed was: 
System.Net.WebPermission 
The Zone of the assembly that failed was: 
MyComputer 

而且我想我可能有System.IO未来的问题了。

我在CAS上看了一眼,我完全模糊不清,我不知道我必须更改哪个策略文件,我必须更改哪些代码组以及如何更改。 我的理解是,这是用于自定义代码(在的rssrvpolicy.config)代码组:

<CodeGroup 
    class="UnionCodeGroup" 
    version="1" 
    PermissionSetName="Execute" 
    Name="Report_Expressions_Default_Permissions" 
    Description="This code group grants default permissions for code in report expressions and Code element.> 

         <IMembershipCondition 
           class="StrongNameMembershipCondition" 
           version="1" 
           PublicKeyBlob="002400...CAEDDA2" 
         /> 
</CodeGroup> 

而只是设定PermissionSetName到Fulltrust不作任何改变。

回答

0

您应该在代码组中尝试PermissionSetName =“FULLTRUST”。

1

对于任何遇到此问题的人(事实发生一年半后),如果您在尝试从BIDS查看报告时收到此异常,则需要更新Visual Studio的PrivateAssemblies中的RSPreviewPolicy.config文件目录。

有三个安全策略文件需要修改以便像这样使用(表达式或自定义程序集中的自定义代码)。可以找到详细的注释(包括对放置新的CodeGroup元素的位置非常重要的注意事项!!)在MSDN页面上(截至今天)“Using Reporting Services Security Policy Files”。安全配置文件是报表服务器配置(rssrvpolicy.config),报表管理器配置(rsmgrpolicy.config)和报表设计器配置(RSPreviewPolicy.config)。

对此的一个很好的测试是每次更新一个,并在每次更新后测试所有三个(将报告部署到您的报告服务器实例当然:)。