Solved

Unauthorized access

Posted on 2011-03-17
7
506 Views
Last Modified: 2012-05-11
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);

Open in new window

0
Comment
Question by:YZlat
  • 4
  • 3
7 Comments
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35159732
Sure you're running as the user you think you are (i.e. maybe you have impersonation on and are running as the user)?  Try putting a Response.Write(Environment.UserName); in an aspx page somewhere as a test.

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.
0
 
LVL 35

Author Comment

by:YZlat
ID: 35159818
Environment.UserName returns ASPNET
0
 
LVL 35

Author Comment

by:YZlat
ID: 35159844
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
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35160038
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?
0
 
LVL 35

Author Comment

by:YZlat
ID: 35160296
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:\>
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
ID: 35164771
I'm unable to duplicate your issue...

Is it possible the AppPool is running as LOCALUSER\ASPNET but the file's NTFS permissions are for DOMAINUSER\ASPNET?  What's in your web.config?
0
 
LVL 35

Author Closing Comment

by:YZlat
ID: 35165127
Your comment helped me to find a solution. I forgot to diable anonymous access in IIS
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question