您的位置:首页 > 编程语言 > ASP

解决asp.net访问某个文件夹没有权限(转)

2013-04-06 11:31 429 查看
private void SetRight(string folderpath)
{
bool result = false;
DirectoryInfo folder = new DirectoryInfo(folderpath);
folder.Attributes |= FileAttributes.Normal;
folder.Attributes &= ~FileAttributes.Hidden; // remove the folder Hidden attribute
folder.Attributes &= ~FileAttributes.ReadOnly;// remove the folder ReadOnly attribute
DirectorySecurity foldersecurity = new DirectorySecurity();
FileSystemAccessRule filerule = new FileSystemAccessRule("INTERACTIVE", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow);
FileSystemAccessRule filerule1 = new FileSystemAccessRule("NETWORK SERVICE", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow);
FileSystemAccessRule filerule2 = new FileSystemAccessRule("NETWORK", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow);
foldersecurity.ModifyAccessRule(AccessControlModification.Add, filerule, out result);
foldersecurity.ModifyAccessRule(AccessControlModification.Add, filerule1, out result);
foldersecurity.ModifyAccessRule(AccessControlModification.Add, filerule2, out result);
folder.SetAccessControl(foldersecurity);
}


注:folderpath为文件夹路径,将需要获得权限的文件夹路径传入方法即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐