Security Issue - Displaying pdf files from SQL Server

Discussion in 'Site Programming, Development and Design' started by dpcolgan, Jul 29, 2010.

  1. dpcolgan

    dpcolgan .net Programmer

    Hi Everyone. I don't get this error locally so I'm assuming it has something to do with the trust level. Nothing I've tried seems to correct it though.

    I used the following in the system.web section of my web.config
    <securityPolicy>
    <trustLevel name="Full" policyFile="internal" />
    </securityPolicy >

    The exception is:
    Security Exception
    Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

    Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.


    The code running is:
    Dim sFilePath As String
    Dim buffer As Byte()
    Dim mydata As New DCHS_Data.DCHSCore_SQL_BaseData
    Using conn As SqlConnection = mydata.Return_New_Connection()
    'conn.Open()
    Using cmd As New SqlCommand("Select Newsletter_File from DCHSCore_Newsletters where Newsletter_Current='True'", conn)
    buffer = cmd.ExecuteScalar()
    End Using
    conn.Close()
    End Using
    sFilePath = System.IO.Path.GetTempFileName()
    System.IO.File.Move(sFilePath, System.IO.Path.ChangeExtension(sFilePath, ".pdf"))
    sFilePath = System.IO.Path.ChangeExtension(sFilePath, ".pdf")
    System.IO.File.WriteAllBytes(sFilePath, buffer)
    Dim act As Action(Of String) = New Action(Of String)(AddressOf OpenPDFFile)
    act.BeginInvoke(sFilePath, Nothing, Nothing)

    Private Shared Sub OpenPDFFile(ByVal sFilePath As String)
    Using p As New System.Diagnostics.Process
    p.StartInfo = New System.Diagnostics.ProcessStartInfo(sFilePath)
    p.Start()
    p.WaitForExit()
    Try
    System.IO.File.Delete(sFilePath)
    Catch
    End Try
    End Using

    End Sub

    I'm in a bind and need a fix for this quickly. Anyone have any ideas?
     
  2. dpcolgan

    dpcolgan .net Programmer

    Hi... changing the webconfig to ...

    <system.web>
    <trust level="Full" />
    </system.web>

    Makes the error go away but now the file does not open...
     
  3. Ray

    Ray

    You have a URL for us to look at?
     
  4. dpcolgan

    dpcolgan .net Programmer

    Last edited by a moderator: Oct 14, 2015
  5. Ray

    Ray

    I'm not seeing what you're seeing. I pulled up your page and everything looks like its working. Have you tried viewing your site on another browser?
     
  6. dpcolgan

    dpcolgan .net Programmer

    Last edited by a moderator: Oct 14, 2015
  7. Ray

    Ray

    I'm running through your tests and this is what I am getting...

    Newsletters

    No past newsletters have been loaded yet. The current newsletter can be found in the navigation menu at the left under 'Current Newsletter'.


    I'm still not clear on what your application is suppose to do but the message indicates that you first need to upload a current newsletter.

    Sorry, you're not giving me enough information to really troubleshoot this.
     

Share This Page