YZlat
asked on
Unauthorized access
When I run the code below I get an unauthorized access exception. I checked the file permissions and ASPNET user has access rights for the file. What am i doing wrong?
FileSecurity fs = File.GetAccessControl(path); <--ERROR HERE
fs.SetAccessRuleProtection(false, false);
File.SetAccessControl(path,fs);
ASKER
Environment.UserName returns ASPNET
ASKER
also if I use File.Exists(path), it returns false even though file does exist. That usually happens when the user does not have sufficient rights, so it's a permissions issue. I just can't figure out what's the problem
Sure that you don't have any overriding "Deny" permissions, and ASPNET has at least "Read Permissions" right? Can you run the command-line "cacls <path to file>" and post the output?
ASKER
here is the output:
C:\test\MyFile.txt
CHOP-EDU\ASPNET:C
CHOP-EDU\ASPNET:C
CHOP-EDU\myusername:F
BUILTIN\Administrators:F
NT AUTHORITY\SYSTEM:F
C:\>
C:\test\MyFile.txt
CHOP-EDU\ASPNET:C
CHOP-EDU\ASPNET:C
CHOP-EDU\myusername:F
BUILTIN\Administrators:F
NT AUTHORITY\SYSTEM:F
C:\>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Your comment helped me to find a solution. I forgot to diable anonymous access in IIS
I believe you also will need at least traverse rights for any folders in the path, and list files right for the immediately containing folder, and read permissions right for the file itself.