0

我尝试了多种方法这是我最新的方法,我试图不触发错误但无济于事我仍然收到 FileIOPermission 错误

完整错误是

请求“System.Security.Permissions.FileIOPermission、mscorlib、Version=4.0.0.0、Culture=neutral、PublicKeyToken=b77a5c561934e089”类型的权限失败

我正在使用的代码如下

    Dim permissions As New Security.PermissionSet(Security.Permissions.PermissionState.None)
    permissions.AddPermission(New Security.Permissions.FileIOPermission(Security.Permissions.PermissionState.Unrestricted))
    permissions.AddPermission(New Security.Permissions.SecurityPermission(Security.Permissions.SecurityPermissionFlag.Execution))
    permissions.AddPermission(New Security.Permissions.SecurityPermission(Security.Permissions.SecurityPermissionFlag.Assertion))
    permissions.Assert()
    ReportViewer1.LocalReport.SetBasePermissionsForSandboxAppDomain(permissions)

    Dim asm As Reflection.Assembly = Reflection.Assembly.Load("ReportingServiceUtils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cca1b177d76f2036")
    Dim asm_name As Reflection.AssemblyName = asm.GetName()
    ReportViewer1.LocalReport.AddFullTrustModuleInSandboxAppDomain(New Security.Policy.StrongName(New Security.Permissions.StrongNamePublicKeyBlob(asm_name.GetPublicKeyToken()), asm_name.Name, asm_name.Version))

dll中使用的代码如下

Public Sub Add(ByVal group As String, ByVal groupCurrentPageNumber As String)
    Try
        If _GroupWithRunningMaxPageNumber.ContainsKey(group) Then
            _GroupWithRunningMaxPageNumber(group) = groupCurrentPageNumber
        Else
            If _GroupWithRunningMaxPageNumber.Count = 0 Then
                Dim fileName = "C:\Working Folder\ms-dot-net-report-viewer-group-pagenation\ReportingServiceUtils\test.xml"
                sw = New System.IO.StreamWriter(fileName, False)
                sw.WriteLine("<root>")
                sw.WriteLine("</root>")
                sw.Close()
                sw.Dispose()
            End If
            _GroupWithRunningMaxPageNumber.Add(group, groupCurrentPageNumber)
            sw.WriteLine("<Group  current='" & group & "' lastPage='" & CStr(groupCurrentPageNumber) & "'/>", 1, 1)
            sw.Close()
        End If
    Catch ex As Exception
        Throw ex
    End Try
End Sub

有没有人看到下面的代码有什么问题

4

2 回答 2

0

我找到了解决方案,当我找到的时候很有趣。下面的 1 行解决了无法从报告中访问文件的问题。

Dim auth As New System.Security.Permissions.FileIOPermission( System.Security.Permissions.PermissionState.Unrestricted)

于 2012-10-15T09:00:01.050 回答
0

使用PermissionSet

      var sec = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);

      ReportViewer1.LocalReport.SetBasePermissionsForSandboxAppDomain(sec);

您可以轻松地从转换C#VB.net

于 2015-11-13T08:18:03.913 回答