SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

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

Last post 01-10-2008 4:04 PM by ChristophWille. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 05-06-2006 11:19 PM

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

    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.
  • 05-13-2006 12:05 PM In reply to

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

    Hi,

    Build a version of the library that doesnt have strong naming will solve the problem I think.

    hth, -jr-

  • 05-19-2006 10:18 PM In reply to

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

    do I have to edit the source code of the #ziplib for this? Downloaded the code but can't find a project file in the src directory.
  • 06-08-2006 1:26 AM In reply to

    • r0bbyw
    • Not Ranked
    • Joined on 06-07-2006
    • Posts 1

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

    Hi creator1988 - did you ever sort this out? I am experiencing the same issue when moving to my clients host from my development system?

    Regards Rob

  • 04-15-2007 9:50 PM In reply to

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

    Hello, I have the same problem with SharpZipLib component, it works ok on my localhost, but after uploading on the webhosting , I get
    That assembly does not allow partially trusted callers.
    Can anybody help, please?
    Thank you a lot, Iva
     
  • 04-16-2007 9:05 AM In reply to

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

    Hi,

    Google finds the best descriptions I am sure.  For example (http://msdn2.microsoft.com/en-us/library/8skskf63(vs.71).aspx) The library must be modified to allow working under some partially trusted scenarios or you can work around it possibly in non-gac/strong named ways.

     Over to you.

  • 06-19-2007 11:16 AM In reply to

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

    I've finally been able to fix this problem after taking over day to solve.

    After speaking to some people on another forum who directed me to this post i though i would leave a message on how solve this issue:

    1) Download the source code & examples from http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx

    2) Unzip and open ICSharpCode.SharpZLib.sln

    3) Under ICSharpCode.SharpZLib open AssemblyInfo.cs & add [assembly: AllowPartiallyTrustedCallers] with using System.Security;

    Then rebuild the project, you get some errors this is due to the examples bit I just deleted that selection.

     4) Open up the SharpZipLib folder and your now find a Bin folder and inside that will be a new ICSharpCode.SharpZipLib.dll.

    5) Copy that into your web application & zip away
     
    And that's how i resolved this security exception. Hope it helps some one
     

    Chrismogz :-)

     

  • 01-10-2008 12:31 PM In reply to

    • firthy
    • Not Ranked
    • Joined on 01-10-2008
    • Posts 1

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

    Hi Chrismogz,

    I'm having the exact same problem, so thanks for publishing the solution. However unfortunaly i dont currently have a copy of vs2005 (i'm waiting for 2008 to be released, so i'm using vwd 2008) so l cant compile the dll. i would much appreciate if you could put a copy of your dll up somewhere?

    I've now spent well over a day on this, all i want to do is zip some files.....

    Thanks 

    firthy ;~(

     

  • 01-10-2008 4:04 PM In reply to

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

    Please do not add the APTCA attribute to SharpZipLib (this is insecure). Instead, remove the signing attribute from SharpZipLib (also in AssemblyInfo.cs) and then copy the resulting assembly to your \bin directory instead of installing it into the GAC.

    Chris

Page 1 of 1 (9 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.