File access question

  • Thread starter Thread starter Jason Hurder
  • Start date Start date
J

Jason Hurder

Hello folks,

I am experiencing a rather strange problem. I have written a service
that attempts to open a file on a network share via a FileStream object.
When I try to open the file from my service, I get the "Access is
denied" error. However, if I try to open the file from a GUI
application, I can open the file without problem. I've tried using the
FileIOPermissions object to get around the error with no luck. Obviously
I am missing something very fundamental, the file is accessible to
'Everyone'. Does anybody know what I am doing wrong? Thank you,

Jason
 
Hi Jason

Maybe it's rather a Windows than a .NET issue. The service may not have
enough privilegies to access the folder while your UI application (which
runs under the context of your user account) does...

Regards

Philipp
 
You are probably running into CAS issues. Fileshare is considered
LocalIntranet_Zone even if it is shared from your local computer. You
probably need to go to the .Net configuration tool and give that share a
special permissions. The tool is under aministrative tools, .Net
Framewwork 1.1 Configuration. Go to runtime security policy, Machine,
All_code and Add a child code group. Give it a name then on the choose a
condition tab select URL. In the bottom text field put the path to the
file share. I.E. file://F:/*. On the next tab select the permission set.
Leave it at FullTrust if you want all permissions. Now you should get no
errors accessing the file share.

Good Luck
Leon Lambert
 
"Access denied" errors are due to Windows permissions denials, not CAS
permission denials, so altering the CAS policy will not resolve this
problem.
 
Manipulating FileIOPermissions will not help resolve this exception since
"access denied" errors are caused by Windows permissions restrictions and
have nothing to do with .NET code access security.

A couple of questions:

1. If you launch the service using the same user credentials with which you
can open the file via the GUI application, can the service open the file?

2. Are you sure that "everyone" access is truly applied, or does this
reflect just the permissions on the share, as opposed to the Windows ACL on
the actual file? Access to a file via a share will be determined by the
intersection, not the union, of the permissions on the share and the file
itself.
 
Back
Top