.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

DirectorySecurity / calculating effective rights for the current windows user?

Posted By:      Posted Date: October 25, 2010    Points: 0   Category :.NET Framework

How do you calculate the effective rights for the current windows user and a specified directory?  I see how you can retrieve the DACL for a Directory using: Directory.GetAccessControl.  

I see that you can get all the access rules for the DACL using: 

var authRules = myDirectorySecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));


This seems to return all acess control entries for the given DACL.  I need to determine the effective rights for the current windows user against a give directory.

How can I retrieve or calculate the effective rights for a given user on a given folder? I basically need to determine if the current windows user has read/write/delete permissions for a given folder.


















View Complete Post

More Related Resource Links

How to get current user session in Windows application C#?



I am trying to create a Windows Application similar to facebook friend finder.exe in .NET. The steps I have followed to achieve this is as follows:

1. I have created a webservice containing webmethod SaveContacts(string firstname, string lastname, string number, string photo, string email, string userid).


2. I am consuming the webservice in a Windows Form application and calling the above mentioned function.

Now, I want to get the current logged in user ID which through the windows form application which is something tedious to me.

If anyone have any idea how to achieve this. Please help.






Not able to get current windows user in RS2005 (but same code works for RS2000)


We use the following custom code (checkGroupMembership.dll) to get identity of the current windows user and then check if the user is part of a certain group (roleName in code below).  

SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.ControlPrincipal);
WindowsIdentity wi = WindowsIdentity.GetCurrent();
WindowsPrincipal cPrincipal = new WindowsPrincipal(wi);    
isMember = cPrincipal.IsInRole(roleName);

The code above behaves differently for RS2000 vs. RS2005. Both RS2000 and RS2005 are installed on same server. If I use the following code to check the WindowsPrincipal name, I get the expected result (my windows login ID) when called from a report in RS2000 but for RS2005 I get the user id of reporting services.


I have checked rssrvpolicy.config (for both RS2000 and RS2005) and it has the same permission for checkGroupMembership.dll.

Any suggestions on why the same code will get different WindowsIdentity? Where I should look next? Any help would be greatly appreciated.


Adding Current Windows User to Database Encounters Existing User with Same Login


In VS2008 in debug mode, I am using SMO to programatically change the users and permissions on a database. Windows authentication alone is being used. I need to limit access to a administrators group and the current user for whom the database has been dynamically created during the first run of the application within their current Windows environment on the machine. I have no problems creating and assigning the administrators group, but when I try to create the user using the environment's UserDomainName and UserName variables (which would be my creditals) I encounter an inner exception "The login already has an account under a different user name". Before doing running the app, I manually have checked the local server for user and logins with my credentials and programatically looked at each login but have not found any matching credentials. 

Insights and suggestions appreciated.


How to get WIndows Current User without Anonymus Access


Hi All,

We have developed an web application, that should run with Active Directory users. That is working fine in our local machines, but when we hosted this into client environment, we are unable to  get the Current User, it is returning NULL.

Could you please give a solution to us.


Thanks in Advance,

Sateesh Nagalla. 

Creating Sites/Lists/List Items under Current User Context in SharePoint By Using SPUserToken

Usually we do this by performing the action under RunWithElevatedPrivileges method and updating the listitem using SPListItem.SystemUpdate() method (see here). but this approach has its own flaws like (RunWithElevatedPrivileges will run under system account, we cannot use SystemUpdate for SPSite,SPWeb,SPList, since it runs under system we will "CreatedBy" by as SystemAccount).

No ASPNET User in Windows Server 2008?


I have been looking everywhere online regarding this, but have not found a clear answer.


I have an ASP.Net app running on Windows Server 2008, it's basically a reporting app using Crystal Reports. I have encountered a roadblock in regards to rendering some pages. When I run the app in Visual Studio(on the same 2008 machine) everything works perfectly. Yet when I publish it and run it live the reports will not display correctly, I get a message saying Failed to render page.


I looked this error up in the Crystal Reports website and the fixes they have there refer to giving the windows "aspnet" user full access rights to certain folders on the machine. I would be happy to do this, however there is no aspnet user in Windows Server 2008.


I installed the server and set its role to be Web Server. I also checked all the options regarding ASP.Net and IIS 6 compatibility. Yet there is no ASPNET username anywhere.


Did I set the server up wrong? or do I have to do something within ASP.Net to  create this user and then give it rights? 

Least Privilege: Teach Your Apps To Play Nicely With Windows Vista User Account Control


User Account Control in Windows Vista keeps the OS safe from intentional and accidental configuration changes.

Chris Corio

MSDN Magazine January 2007

App Fundamentals: Build A Great User Experience With Windows Presentation Foundation


The Windows Presentation Foundation application model distinguishes between standalone and browser applications and between menu driven and hyperlink driven navigation, resulting in a more satisfying experience for your users.

Michael Weinhardt

MSDN Magazine October 2006

Resource File: Windows Media 9 Series Digital Rights Management


If you have an application that handles Windows Media content and you need an effective way to track content usage, Windows Media 9 Series now offers Digital Rights Management (DRM). It allows you to take advantage of the peer-to-peer distribution model and still redirect users back to your app once they have downloaded your content (prior to viewing).

MSDN Magazine May 2003

Windows Forms: Developing Compelling User Controls that Target Forms in the .NET Framework


In the beginning, writing controls meant dealing with Windows messages. Then came Visual Basic controls, which introduced methods, properties, and events. Later, ActiveX controls, which ran atop COM, became popular. While each innovation in control writing brought more flexibility, nothing has matched the versatility of the new .NET Windows Forms controls and Web Forms controls. This article, the first of a two-part series, introduces the reader to Windows Forms, beginning with their inheritance from one of the .NET CLR base classes, which makes control creation much faster than before. Control programming is illustrated through the development of a login control. The equally flexible Web Forms controls will be covered in Part 2.

David S. Platt

MSDN Magazine April 2002

Windows 2000 UI Innovations: Enhance Your User's Experience with New Infotip and Icon Overlay Shell


Windows 2000 includes some helpful new UI features you can customize and implement in your own applications. In this article you'll see how to provide infotips for files, after making the appropriate registry entries. Then create a custom column handler extension, resulting in a new column for the Explorer's Details view. In order to further extend the shell, additional UI goodies will also be examined and implemented including: search handlers, cleanup handlers, folder customizations using property sheet handlers and icon overlays, and context menu shell extensions. All the code samples are rolled up into a handy package which we've named, by tradition, ShellToys.

Dino Esposito

MSDN Magazine March 2000

how to store User Rights Information in asp.net



Please guide me how to store user rigths inforamtion in asp.net MVC Application

Here my User permission  information look like

UserID LoginID          UserName             Page  Permission     Role 

yahoo@yahoo.com Mohammed Askar Quote Edit                Admin 
yahoo@yahoo.com Mohammed Askar Quote Delete            Admin 
yahoo@yahoo.com Mohammed Askar Quote Verify             Admin


gamil@gamil.com   Mr. X                      Quote Cancel  &nbs

Knowing the event occured in user control in current page




      My web application has user control which uses third party controls called Devexpress controls. The user control is a menu  and is part of the Master page. It is placed there because this needs to be available in all the pages. My user controls raises a even on item clicked. Now, My question is that Is there any way to know that the event has occurred in page_load of the current page in which I am in?

Forms based users being prompted for windows authentication login for My Sites photos in user lists

Here's an issue I didn't see coming for our forms based authentication users. 

We have a web application extended to an external url to handle forms based authentication for users outside of our domain. Our setup looks like this...

Internal Users/Windows Authentication - moss.domain.com
External Users/Forms Based - mossext.domain.com
My Site for Internal Users - mysites.domain.com

When our forms based users are accessing user lists, or discussion pages that display user pictures, they are getting a windows authentication login for our internal users (mysites.domain.com) who have populated their my site with personal photo.

How do we fix this? 

=User!UserID from windows authentication using table from another database



i'm using sql server 2005, sql server business intelligence development studio for my reports and deploy them in my wss3.0 site.

what i'm trying to do is i'm trying to restrict wich users can see specific data within a report.

now, the thing is. the report gets the data out of my DB1 database and my windows authenticated user are in the WSS_content database.

when i deploy my report in my wss3 site. it gets the user that is loged in. but of course it does not display any data because the tables are not in the same database.

does someone knows how to do this?

create current user filter in sharepoint designer or wss3

hi, how can i create a current user filter in sharepoint designer?

The name 'User' does not exist in the current context.


Hey guys,

I've got a literal control to display the username of the user logged into our companies intranet system, originally I had a LoginName control but couldn't get strip to remove the domain from the username (as the format is domainname\username) so I'm trying it this way.

    protected void Page_Load(object sender, System.EventArgs e)
        string[] Parts = User.Identity.Name.Split("\\");

        if (Parts.Length == 2)
            loginName.Text = Parts[1];
            loginName.Text = User.Identity.Name;


    protected void Page_Load(object sender, System.EventArgs e)
        string[] Parts = User.Identity.Name.Split("\\");
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend