0

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
Stanton
  • 1,334
  • 4
  • 18
  • 32
  • From where is your application attempting to read a file when this exception is thrown? i.e.: What is the file path that the `Page_Load` method in `uploader \index.aspx.vb` is passing to `ZipFile.Read`? – Nicole Calinoiu Apr 30 '14 at 12:44
  • @Nicole Calinoiu, thanks for your reply. I've tried putting the file in a few different places, including the same directory where my app files (aspx files) reside. I figured I'd surely have permission to read it from there. If I ever get it working, my users will need to open zip files located on their local machines. – Stanton May 01 '14 at 16:02

2 Answers2

0

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.

makemoney2010
  • 1,222
  • 10
  • 11
  • Thanks for your reply. But as I said, this utility will need to reside on my client's server, where I don't have access to the IIS settings. Any idea how I can do it with my web.config file? – Stanton Apr 29 '14 at 21:37
  • you can't.Permission can be set only via iss or control panel or power sheel and advanced tool or last solution ask to your hosting setup right permission for you which is the more simply way. – makemoney2010 Apr 29 '14 at 21:42
  • @Stanton one stuff when you talking about app directory do you mean root or App_Data.You may add permission to App_Data and try on this but i dont think it will fix the issue. – makemoney2010 Apr 29 '14 at 21:44
  • Thanks Money. I think you may be right. I guess I'm sunk. – Stanton Apr 29 '14 at 21:55
0

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.

Stanton
  • 1,334
  • 4
  • 18
  • 32