Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

[ASP.Net] Security Exception (partially trust callers) in Medium Trust

$
0
0
I'm currently building a photoalbum and I want to unzip an uploaded file. Well, on my desktop computer it all worked fine (Fully trust zone), but after uploading it to my hosting company (Medium trust zone) I get the following security exception:

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: That assembly does not allow partially trusted callers.

I've contacted my hosting provider as suggested in the error message. Their reaction was that I had to use a component that doesn't require partially trusted callers as they won't edit the trust level.

I'm jusing the following code to unzip the files which are located in '~\Temp.zip', the application has fully write properties in the directory it unzips the files (~\Temp\*).

-----------------------------------------------------------------------------------
Imports ICSharpCode.SharpZipLib.Zip
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging

Partial Class CMS_AddFoto
Inherits System.Web.UI.Page


Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Dim s As ZipInputStream
Dim theentry As ZipEntry
Dim filename As String

[...]
        s = New ZipInputStream(File.OpenRead(Server.MapPath("temp.zip")))
theentry = s.GetNextEntry

Do Until theentry Is Nothing
filename = Path.GetFileName(theentry.Name)
Unzip("temp.zip", "Temp\", filename)
theentry = s.GetNextEntry
Loop

[...]

End Sub

Public Sub Unzip(ByVal ZipFile As String, ByVal UnzipToFolder As String, ByVal Extract_File As String)
Dim z_file As New ZipFile(File.OpenRead(Server.MapPath(ZipFile)))
Dim z_entry As ZipEntry = z_file.GetEntry(Extract_File)
Dim nbyte As Int32 = 0
Dim read_stream As Stream = z_file.GetInputStream(z_entry)
Dim write_stream As New FileStream(Path.Combine(Server.MapPath(UnzipToFolder), z_entry.Name), FileMode.Create)
Dim bin_write As New BinaryWriter(write_stream, System.Text.Encoding.ASCII)
Dim zip_data(1024) As Byte

Do
nbyte = read_stream.Read(zip_data, 0, 1024)
If nbyte = 0 Then Exit Do
bin_write.Write(zip_data, 0, nbyte)
Loop

read_stream.Close()
bin_write.Close()
write_stream.Close()
End Sub
End Class

-----------------------------------------------------------------------------------

I'm using version 0.84 of the #ziplib.

I would really appreciate any help on how to get things work.

Viewing all articles
Browse latest Browse all 1764

Trending Articles