Reputation: 1
Let me first explain the scenario: we have a Synology NAS device, and we're a small team.
Every time we start a new project, we have to manually create a main folder in the Projects
directory, then create 9 subfolders under it, and finally configure permissions for each. This process takes a lot of time, so I decided to write a C# program to automate it.
The program consists of two windows - in the first window, I input the name of the main project folder, and the program automatically creates the main folder and its 9 subfolders in the Projects
directory.In the second window, I set permissions for 3 predefined users. When I click the "Apply" button, the program is supposed to configure the permissions.
The folder creation part works perfectly, but the program throws an error when attempting to set permissions.To debug the issue, I created a simple C# console application and manually tested it with the following code:
using System;
using System.IO;
using System.Security.AccessControl;
class Program
{
static void Main(string[] args)
{
string userName = @"192.168.1.120\\Mehmet";
string path = @"\\192.168.1.120\\va+ PROJECTS\\Deneme";
DirectorySecurity directorySecurity = Directory.GetAccessControl(path);
directorySecurity.AddAccessRule(new FileSystemAccessRule(userName, FileSystemRights.FullControl, AccessControlType.Allow));
Directory.SetAccessControl(path, directorySecurity);
Console.WriteLine("Permissions updated successfully.");
}
}
However, I get this error:
System.Security.Principal.IdentityNotMappedException: Some or all identity references could not be translated.
The NAS device is located at 192.168.1.120. I've tried using the IP address, the device name, and other variations, but none of them worked. I suspect the system is unable to resolve the user.
I can manually update the permissions by right-clicking the folder, going to "Properties > Security," and editing them directly, so my account does have the necessary permissions. Both devices are in the same WORKGROUP.
I believe I've shared all the relevant details. Can anyone help?
Upvotes: 0
Views: 73