setting up filesystem permissions

房东的猫 提交于 2019-12-12 20:15:48

问题


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Security.AccessControl;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string Directoryd = "D:";
            string mydirectory = Directoryd + "\\" + "rs\\";
            if (!Directory.Exists(mydirectory))
            {
                Directory.CreateDirectory(mydirectory); 
            }
            DirectoryInfo di = new DirectoryInfo(mydirectory);
            DirectorySecurity ds = di.GetAccessControl();


            ds.AddAccessRule(new FileSystemAccessRule(@"*",FileSystemRights.FullControl,AccessControlType.Allow));
           di.SetAccessControl(ds);





        }
    }
}

this is my code when i execute this the pop up is showing that Actually, this code is to create a folder rs and set its permission to deny full control but on running the error come with the message Some or all identity references could not be translated. What is the error?


回答1:


You should change the following line:

 ds.AddAccessRule(new FileSystemAccessRule(@"*",FileSystemRights.FullControl,AccessControlType.Allow));

to:

 ds.AddAccessRule(new FileSystemAccessRule(@"Everyone",FileSystemRights.FullControl,AccessControlType.Allow));

Also if you look at the following Everyone Group there is an answer a bit further down that suggests you should use SSID's instead of the names.




回答2:


Try the group "Everyone", not *.



来源:https://stackoverflow.com/questions/11472974/setting-up-filesystem-permissions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!