MarkWThompson
asked on
DLL update causes FileIOPermission Error
I've an ASP.NET 3.5 app running for six months or so using the IONIC.ZIP.DLL (added by Right-clicking App, Add Reference and pointing to the DLL.
When I execute the attached code I get the following error:
Request for the permission of type 'System.Security.Permissio ns.FileIOP ermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193 4e089' failed.
In the config I have:
<authentication mode="Windows"/>
<identity impersonate="true" userName="TestDomain\TestU ser" password="TestPassword"/>
Again, this has been running for the last 6 months w/o problems. I did, however, recently update the DLL to a newer version. I was running v1.7.2.12 and now have 1.9. I'm guessing this is what started the problem.
This works perfectly fine from my local PC, but when deployed onto my server is when I receive the error.
When I execute the attached code I get the following error:
Request for the permission of type 'System.Security.Permissio
In the config I have:
<authentication mode="Windows"/>
<identity impersonate="true" userName="TestDomain\TestU
Again, this has been running for the last 6 months w/o problems. I did, however, recently update the DLL to a newer version. I was running v1.7.2.12 and now have 1.9. I'm guessing this is what started the problem.
This works perfectly fine from my local PC, but when deployed onto my server is when I receive the error.
Dim sFilename As String = "\\SERVER1\PAPERS\ZIPTEST\test.zip"
If Not File.Exists(sFilename) Then
lblError.Text += "FILE NOT FOUND : " & sFilename
Exit Sub
End If
Try
Dim oZip As ZipFile = ZipFile.Read(sFilename)
Try
lblError.Text += oZip.Entries.Count.ToString
Catch ex As Exception
lblError.Text += "EX3: " & ex.Message & "<br><br>"
End Try
Try
oZip.ExtractAll("\\VENUS\PAPERS\ZIPTEST\", ExtractExistingFileAction.OverwriteSilently)
Catch ex As Exception
lblError.Text += "EX2: " & ex.Message & "<br><br>"
End Try
oZip.Dispose()
Catch ex As Exception
lblError.Text += "EX1: " & ex.Message & "<br><br>"
End Try
lblError.Text += "DONE! " & Now.ToString("MM/dd/yy HH:mm:ss")
ASKER
Unfortunately, no. So I must have done someone else, but I have no idea what it could have been.
ASKER
The line that gives the exception is:
Dim oZip As ZipFile = ZipFile.Read(sFilename)
So where it tries to access the file. File.Exists("Filename") works just fine, however.
Dim oZip As ZipFile = ZipFile.Read(sFilename)
So where it tries to access the file. File.Exists("Filename") works just fine, however.
Have you checked to make sure that the file permissions are correct? I can't remember if the Internet Guest Acccount, the ASP.NET account or both need permission to the file. Give that the file is on a different computer, the logins and passwords would have to be the same.
Also, can you try the code below and see if it works? If it does, I'm sure it'll just spit out nonsense, I'm just trying to test if it's an issue with accessing the file or with IONIC.ZIP.DLL.
Also, can you try the code below and see if it works? If it does, I'm sure it'll just spit out nonsense, I'm just trying to test if it's an issue with accessing the file or with IONIC.ZIP.DLL.
Dim curFileInfo As New FileInfo(sFilename)
Dim curStreamReader As StreamReader = curFileInfo.OpenText()
Response.Write(curStreamReader.ReadToEnd)
ASKER
quizwedge: When I run your code it acts as if I want to download the file. So I'm assuming this is because it IS actually able to access the file.
It seems to me that the issue is something to do with IONIC.ZIP.DLL. I haven't used it, but I found the following question posted (http://dotnetzip.codeplex.com/discussions/82867?ProjectName=dotnetzip) which discussed giving Ionic full trust using CASPOL. You can see more about CASPOL at http://msdn.microsoft.com/en-us/library/cb6t8dtz(v=vs.80).aspx
ASKER
Quizwedge: I'm poking around exactly how to give fulltrust to the dll via Caspol.
Until I do, however, I'm still inclined to think that this is not the problem as it was running fine just a few days ago (and still works fine from my local PC).
I'm bettng I changed something on the Server in IIS which has screwed this all up, but have yet to figure out what :-(
Until I do, however, I'm still inclined to think that this is not the problem as it was running fine just a few days ago (and still works fine from my local PC).
I'm bettng I changed something on the Server in IIS which has screwed this all up, but have yet to figure out what :-(
One option would be to try writing and reading a file to the same directory. That would confirm for sure that ASP.NET had the permissions it needed. At that point it'd be pretty conclusive that it was something to do with IONIC even if it was something to do with IIS and permissions for IONIC.
You may want to add a tag and/or zone for IIS to see if you can pull in any IIS experts that have experience in this area.
You may want to add a tag and/or zone for IIS to see if you can pull in any IIS experts that have experience in this area.
ASKER
I wrote the following code and it execute just fine. It must have something particular to do with the IONIC dll and IIS (of course, I'm still guessing).
Dim sFilename As String = ""
sFilename = "\\VENUS\PAPERS\ZIPTEST\" & Format(Now, "yyyy-MM-dd HH-mm-ss-ff") & " - " & Environment.MachineName.ToUpper & ".txt"
Try
If IO.Directory.Exists("\\VENUS\PAPERS\ZIPTEST") Then
Dim oW As New IO.StreamWriter(sFilename)
oW.WriteLine("FROM: " & asFrom)
oW.WriteLine("TO: " & asTo)
oW.WriteLine("SUBJECT: " & asSubject)
oW.WriteLine("BODY: " & asBody)
oW.Close()
End If
Catch ex As Exception
'** CRAP **
End Try
End Sub
I thought of one more test I thought of to confirm that it's something in IIS that needs to be fixed. Build a regular Windows VB.NET app that uses IONIC and run it on the server. If It can do the zipping and unzipping from the remote directory, then it seems pretty conclusive that it's something with IONIC in IIS.
I'm guessing you're on the right track that the answer lies in IIS. I found someone who had a similar issue (which came down to IIS not trusting IONIC) and built a workaround: http://stackoverflow.com/questions/4432370/why-cant-my-aspx-pages-access-directories-on-the-webserver-iteself Seems to me the better solution would be to have IIS trust IONIC. I think to do that, you use Caspol, but I'm not positive. If Caspol doesn't work, I'd have to rely on Google.
I'm guessing you're on the right track that the answer lies in IIS. I found someone who had a similar issue (which came down to IIS not trusting IONIC) and built a workaround: http://stackoverflow.com/questions/4432370/why-cant-my-aspx-pages-access-directories-on-the-webserver-iteself Seems to me the better solution would be to have IIS trust IONIC. I think to do that, you use Caspol, but I'm not positive. If Caspol doesn't work, I'd have to rely on Google.
ASKER
Yes, I do have another .NET application that uses the IONIC dll. It works fine. It's just the ASP.NET app that's failing.
Since Caspol is not on the server, running this only affects my local dev machine, right?
Since Caspol is not on the server, running this only affects my local dev machine, right?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found something referencing the "blocked" status that can be "unblocked" a while back. I went to the server via File Explorer, Right Click, Properties and "Unblocked" it. *Sigh* Not it.
I also tried reading the Zip file from the local machine -- that didn't work either. So it's not the file or the location that it's accessing -- it's just that IONIC is trying to do anythign to files that is the problem.
I'll research the CASPOL (via the server) and see what I can figure out. I don't want to have to install something on the server to test the CASPOL theory -- as we both know it was working at some point without CASPOL being in the equation. I only wish I know what has/I changed.
I also tried reading the Zip file from the local machine -- that didn't work either. So it's not the file or the location that it's accessing -- it's just that IONIC is trying to do anythign to files that is the problem.
I'll research the CASPOL (via the server) and see what I can figure out. I don't want to have to install something on the server to test the CASPOL theory -- as we both know it was working at some point without CASPOL being in the equation. I only wish I know what has/I changed.
The one reason why I still think CASPOL might offer a solution is because you would have uninstalled and reinstalled DotNetZip on the server. That should have removed any permissions it had.
One other thought is that you may need to reboot IIS and/or the server for the unblocking to take effect.
One other thought is that you may need to reboot IIS and/or the server for the unblocking to take effect.
ASKER
Good idea. I have not revolted the server since I've unlocked it. I'll try that tonight. In addition, I'll create a com dll that does nothing more than create a file on a share and run that from the web server. If it fails I know for sure it's not just an IONIC dll problem and definitely a dll permission problem (I'm pretty sure it is the latter, but I'll try it just to make sure).
For just a brief second I thought it might be a 64 bit vs 32 bit issue -- but both server and dev machine are running 64 bit.
For just a brief second I thought it might be a 64 bit vs 32 bit issue -- but both server and dev machine are running 64 bit.
ASKER
I created a dll that had two simple methods. One to write a test file, and another that referenced IONIC and tried the same code in the web page. The First method succeeded and the 2nd method gave me the exact same error that the second one did.
There must be something very specific about the IONIC dll that IIS doesn't like?
There must be something very specific about the IONIC dll that IIS doesn't like?
ASKER
Finally, it's working. I didn't reboot the server, just restarted the IIS services. And whatever above, below and everything else that was tried seemed to have done the trick. I know I had rebooted the server at one point, but not since the "Unblock" on the DLL. So, I'm going to say (and hope) that it was that process which did the trick.
Thank you for your patience and ideas.
Thank you for your patience and ideas.
ASKER
To be specific, it was the "Unblock" that I believe did the trick.
That's great! Glad it's working now.
Can you do MsgBox alerts or something similar to find out which line it is throwing an error on?