Click here to Skip to main content
16,020,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a website running on my local IIS 7.5 server. The site has two class libraries, call them LibA and LibB. Both are copied to the same sub-folder on build. LibA writes to a text file in the root directory of the website. This works fine. However, when LibB raises an event, which triggers a call to the same function in LibA to write to the same text file, it fails with an exception which says access to the file is denied.

As far as I understand it, both these libraries should be loaded into the same AppDomain, so I don't understand why one library has permissions that the other doesn't. And, given the fact that the actual file writing is always done by LibA, I don't understand why different permissions are required at all.

I have no idea what is going on here. Any help would be gratefully received.


Kind wishes, Patrick
Posted

This may sound like a stupid question, but did your code Close the file before it tried to open it again??

Sometimes "Access Denied" has nothing to do with security at all. The file can be locked by a process, be it your own or a different one, and you'll get this message.
 
Share this answer
 
Comments
Maciej Los 21-Mar-13 17:12pm    
There are no stupid questions, there are stupid answers, but your answer is perfect!
+5!
Patrick Skelton 22-Mar-13 13:02pm    
Thank you for the reply.

The access is wrapped in a lock() {} statement and the file handle is acquired in a using() {} statement, so - in theory - neither of your suggestions should be the problem.

Really stuck with this one. :-(
Dave Kreskowiak 22-Mar-13 13:51pm    
In that case, does the account that ASP.NET is using have write permissions to the folder where the file is going? That's about all I've got.
Patrick Skelton 22-Mar-13 14:06pm    
Mmm ... it seems you are right. It was nothing to do with one library being able to write and the other not. I definitely recall giving IIS_IUSRS adequate permission for this folder, but it seems to have disappeared. It works now.

Oddly though, calls to write to this folder/file were succeeding from Global.asax, even without the permissions in place. Does the Global.asax code run under a different user to the actual pages of the website?
Dave Kreskowiak 22-Mar-13 14:10pm    
It shouldn't be. It's still part of the same code the rest of the site is running.
Try , setting Domain Account as ApplicationPoolIdentity.
 
Share this answer
 
Comments
Patrick Skelton 22-Mar-13 12:49pm    
Thank you for the reply, but it is already set to this.

- Patrick

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900