[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2053
  • Last Modified:

Get Effective Permission using .NET

I want to get the effective permissions of an user on a directory or file by using .NET.
How to get it in C#?
Thank You
0
Amitava_Mukherjee
Asked:
Amitava_Mukherjee
  • 3
  • 2
  • 2
  • +2
2 Solutions
 
lazyberezovskyCommented:
For directory use Directory.GetAccessControl
string identityReference = @"Domain\UserName";
string path = "file.txt";

FileSecurity fileSecurity = File.GetAccessControl(path);
foreach(FileSystemAccessRule rule in fileSecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{                 
    if(rule.IdentityReference.Value == identityReference)
    {
        // use rule.FileSystemRights and rule.AccessControlType                                      
    }                
}

Open in new window

0
 
Amitava_MukherjeeAuthor Commented:
This function works if I explicitely give rights to a particular user on the file/folder, but not the effective rights.
Please provide some C# code so that I can get the Effective Permission.
Sorry for the delayed response.
0
 
Shahan AyyubSenior Software Engineer - iOSCommented:
I could not get what do you mean about 'EFFECTIVE PERMISSION', but as i understood, check the following web address:


http://stackoverflow.com/questions/130617/how-do-you-check-for-permissions-to-write-to-a-directory-or-file
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Amitava_MukherjeeAuthor Commented:
If I right click a folder and then select Security -> Advanced, I get an 'EFFECTIVE PERMISSION' Tab. Then if I select the user if shows some permissions - I want to get that 'EFFECTIVE PERMISSION'
0
 
Steve BinkCommented:
Here is an article from a guy who went through the same process:

http://www.conarc.com/blog/2010/03/25/programmatically-getting-effective-directoryfile-permissions/

There is not a lot of material on this concept, and I'm inclined to say there is no built-in method of obtaining this information.  This means you have to parse the permissions yourself and recreate it.  While not impossible, that is an algorithm that will take time to get right.  Perhaps you can go back to your concept and re-examine if you *really* need effective permissions to do what you want.
0
 
Bob LearnedCommented:
I believe the resource that would help you is this nice article:

Programmatically Getting Effective Directory/File Permissions
http://www.conarc.com/blog/2010/03/25/programmatically-getting-effective-directoryfile-permissions/
0
 
Steve BinkCommented:
lol...nice..  :)
0
 
Bob LearnedCommented:
Sweet timing!!  Great minds, and all that!!
0
 
Amitava_MukherjeeAuthor Commented:
Thanks for the solution
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now