.NET Security Question
-
I have attempted to use some of the new security classes in .NET 2.0. Question. How can I check the writes of the currently logged in user for a given resource suce as a file/directory. I want to know before taking an action if a user can write to a directory, can the user create a sub directory in a given directory on the network. Here is what I have tried: PUBLIC FUNCTION ReturnCheckMyRightsOnDirectory(XRightsToCheck AS DirectoryPermissions , XPath AS STRING) AS BOOLEAN IF MY.Computer.FileSystem.DirectoryExists(XPath) = FALSE THEN RETURN FALSE END IF TRY DIM DirectoryName AS STRING = XPath Dim dInfo AS NEW DirectoryInfo(DirectoryName) Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl() DIM DirectoryRightToCheck AS FileSystemRights SELECT CASE XRightsToCheck CASE DirectoryPermissions.Create DirectoryRightToCheck = FileSystemRights.CreateDirectories CASE DirectoryPermissions.Read DirectoryRightToCheck = FileSystemRights.Read CASE DirectoryPermissions.Update DirectoryRightToCheck = FileSystemRights.Modify CASE DirectoryPermissions.Delete DirectoryRightToCheck = FileSystemRights.Delete CASE DirectoryPermissions.Write DirectoryRightToCheck = FileSystemRights.Write CASE DirectoryPermissions.Execute DirectoryRightToCheck = FileSystemRights.ExecuteFile CASE DirectoryPermissions.Admin DirectoryRightToCheck = FileSystemRights.FullControl END SELECT dSecurity.AddAccessRule(New FileSystemAccessRule(SystemUserName, DirectoryRightToCheck, AccessControlType.Allow)) dInfo.SetAccessControl(dSecurity) RETURN TRUE CATCH ex As Exception RETURN FALSE END TRY END FUNCTION