Question

I've integrated the DotNetZip dll into an ASP.net/VB project. But when I try to open a file for reading, I get a security exception:

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

I've looked at a ton of places for help on this error (including several on this site), but nothing seems to work. I get the impression that I need to set my application's trust level. When my application is finished it will need to live on my client's server, where I won't have access to their IIS configuration. Some of the sites I've consulted say to do this in my web.config file. From the MSDN and other places, I've tried variations on this:

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

No good. I put my target zip file in the app directory to simplify things, and checked that I have full permissions on that directory. Still no good.

Can anyone tell me how I can set my app's trust level correctly, or if there's something else I need to do? Here's the stack trace in case anyone's interested. And thanks.

[SecurityException: Request for the permission of type    
'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, 
Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& 
stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +61
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights,
 Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, 
SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +644
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare 
share) +66
Ionic.Zip.ZipFile.get_ReadStream() +75
Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf) +46
Ionic.Zip.ZipFile.Read(String fileName, TextWriter statusMessageWriter, Encoding 
Ionic.Zip.ZipFile.Read(String fileName) +11
CodeBehind.Page_Load(Object sender, EventArgs e) in W:\research\httpdoc\uploader
\index.aspx.vb:45
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean 
includeStagesAfterAsyncPoint) +6785
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean 
includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.index_aspx.ProcessRequest(HttpContext context) +37
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& 
completedSynchronously) +75
Was it helpful?

Solution 2

If anyone ever reads this and has the same problem, I switched to another package, the SharpZipLib package available here. Seems to be working without security issues.

OTHER TIPS

You need to check all your iis user and permission on that folder. To do that rdp your server access to iis select site browse the directory.Find the directory which need permission, select it click on it right clik => properties => security tab. Check your user and check if those has the right permission.In not update permission clik on edit in security tab and update permission for the user that you need to has permission to perform this action.Click save/ok i don't rember and try again.It should solve your issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top