Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unauthorized access

Posted on 2011-03-17
7
Medium Priority
?
511 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 1500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

670 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