Solved

Unauthorized access

Posted on 2011-03-17
7
503 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
Comment Utility
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
Comment Utility
Environment.UserName returns ASPNET
0
 
LVL 35

Author Comment

by:YZlat
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 33

Expert Comment

by:Todd Gerbert
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Your comment helped me to find a solution. I forgot to diable anonymous access in IIS
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now