报告中dll中的FileIOPermission错误

时间:2012-10-10 08:58:10

标签: vb.net winforms visual-studio-2010 .net-4.0 report

我尝试过各种各样的方法,这是我最新的方法,我试图不解决错误,但无济于事我仍然得到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

有没有人发现以下代码有什么问题

2 个答案:

答案 0 :(得分:0)

我找到了解决方案,当我这样做时非常有趣。 以下1个班轮解决了无法从报告中访问文件的问题。

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

答案 1 :(得分:0)

使用PermissionSet

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

      ReportViewer1.LocalReport.SetBasePermissionsForSandboxAppDomain(sec);

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