如何利用.NET的DirectorySecurity对象处理目录安全性问题

vmware虚拟机网络连接问题 主机:ubuntu14.04 Vitual Network Editor 阅读详情

处理.NET目录 的一个重要问题是安全性问题,也就是说,你可以让需要访问某个目录的用户访问该目录,而限制其他用户访问该目录。本文详细介绍了目录级的安全控制与设置。

访问控制

使用.NET的Directory类,用户可通过DirectorySecurity对象的下列方法来访问目录的访问控制列表(ACL):

  • GetAccessControl:返回一个目录的Windows ACL作为一个DirectorySecurity对象。
  • SetAccessControl:将DirectorySecurity对象的ACl入口赋予指定目录。

为了正确应用这些方法,需要对DirectorySecurity类有深入的理解,因此下面我们对此作深入讲解。

DirectorySecurity

DirectorySecurity类定义了如何对目录访问进行审计。该类是潜在的Windows文件安全系统(System.Security.AccessControl命名空间的一部分)的一个抽象。

在该系统中,每个目录有一个自由决定的ACL来控制目录访问。同时,一个系统ACL决定对哪些访问控制进行审计。使用两个类FileSystemAccessRule 和FileSystemAuditRule来分别处理目录访问和审计。

FileSystemAccessRule类代表一个潜在的访问控制入口的抽象,访问控制入口用来指定用户账号,提供的访问类型(读、写等等)以及 是许可或拒绝某个权限。同时,该类还指定了如何将访问规则传递给子对象。FileSystemAuditRule类代表了为某个文件或目录定义审计规则的 ACE。

为了通过DirectorySecurity类为某个目录添加一条新规则,需要FileSystemAccessRule 和 FileSystemAuditRule两个类的新实例。我们从访问权限开始,当同DirectorySecurity类一起使用这些类时,需要创建新的 对象实例。列表A 包含了每个类的语法。

第一个参数指定每个应用该规则的用户、组或标识。第二个参数是FileSystemRights列表,用来指定用户(由第一个参数指定)可以进行的 操作,它包含很多可能的取值,包括:CreateDirectories、 CreateFiles、 Delete、 FullControl、 ListDirectory等等。

用于FileSystemAccessRule类的最后一个参数可用来指定用户能否执行参数二的操作。AccessControlType列表包括 两个可能取值:允许和拒绝。用于FileSystemAuditRule类的第三个参数可从AuditFlags列表的Failure、None或 Success中取值来设定审计级别。FileSystemAuditRule类的构造函数是重载的,这个方法是最基本的方法。

目录访问

Directory类可用来处理目录的ACL入口,为此,按照以下步骤进行处理:

  • 通过Directory类的GetAccessControl方法来初始化一个DirectorySecurity对象。
  • 通过DirectorySecurity对象指定目录访问规则。例如,使用AddAccessRule方法可以添加一个新规则。新规则定义为一个FileSystemAccessRule对象,它包含标识(用户、组等),系统权限和ACL。
  • 调用Directory类的SetAccessControl方法来永久的改变ACL。

列表B 中的C#代码对C:盘中每个目录添加一个ACL入口。该入口提供了对特定用户的访问控制(DomainTechRepublicUser)。同时,删除了另一个访问规则,该规则对另一个用户没有任何所有控制(DomainTester)。列表C 包含VB.NET实现的相同功能的代码。

审计追踪

应用Directory类还可以指定目录安全审计规则。审计包含了前面例子中的访问规则处理,这两者的区别是审计使用FileSystemAuditRule类而不是使用FileSystemAccessRule 类。列表D 中的C# 代码包括了前面的例子,此外还增加和删除了目录ACL中的审计规则。列表E 包含了实现同等功能的VB.NET 代码。

efm32 入门.pdf 本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。 立即下载

相关推荐

用Arduino和RC522模块DIY一个NFC门禁卡复制器(附完整代码)

本文详细介绍了如何利用Arduino和RC522模块DIY一个NFC门禁卡复制器,包括硬件连接、软件配置、数据读写技术及完整代码实现。通过本教程,电子爱好者可以深入了解NFC技术,并构建自己的智能门禁系统,适用于家庭安全、办公场所等多种场景。

weixin_33704591的博客 503

C# 给某个文件夹加权限

demo string destinationDirectory = @"C:\Users\XChen32\Desktop\FTAE_Src"; System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(destinationDirectory); FileSystemAccessRule fsar = new FileSystemAccessRule("Users", FileSystemRights.

weixin_43632687的博客 700

生态位宽度计算&可视化展示(R语言)

物种的生态位越宽,该物种的特化程度就越小,倾向于泛化种(generalist species);物种的生态位越窄,倾向于是一个特化种(specialists species)。生态位宽度是指物种(或其它生物单位)在群落中所利用的各种不同资源的总和。本篇所使用为生态位宽度指数即**Levins的生态位宽度指数。

weixin_53705272的博客 4435

C#使用DirectorySecurity的SetOwner设置文件夹所有者只能设为当前用户

看到有人问了这个问题,查询并实验后发现确实有这个问题,测试代码如下: static void Main(string[] args) { try { string folderPath = @"e:\testSecurity"; Directory.CreateDirectory(folderPath); Dir...

weixin_30739595的博客 1502

【液晶专题】从外挂到In-Cell/ On-Cell/ OGS再也不会傻傻分不清楚了

触控技术经历了从外挂式到内嵌式的革新,主要方案包括外挂式(Out-Cell)、OGS、On-Cell和In-Cell。

一点硬件 1253

关于MII、RMII、GMII、RGMII、PHY、网络变压器、RJ45的硬件总结

文章目录前言一、网络传输结构及原理1.以太网的工作原理2.TCP/IP协议3.数据链路层(MAC)二、介质独立接口MII,RMII,GMII,RGMII1.MII(Media Independent interface)2.RMII(Reduced Media Independent Interface)3.GMII(Gigabit Medium Independent)4.RGMII(Reduced Gigabit Media Independent Interface)三、物理层芯片(PHY)二、使用步

weixin_44415816的博客 3万+

C# 判断用户是否对路径拥有访问权限

如何获取当前系统用户对文件/文件夹的操作权限? 1.获取安全信息DirectorySecurity DirectorySecurity fileAcl = Directory.GetAccessControl(folder); 通过Directory.GetAccessControl获取文件夹的权限/安全信息 详细介绍,可参考MSDN官方文档 对文件/...

weixin_33681778的博客 1512

利用Python实现Springer文献关键词爬虫

🔧 如何分析Springer的搜索结果HTML结构🕷️ 编写高性能异步爬虫抓取论文元数据📊 使用Pandas导出Excel🧠 如何处理作者、摘要、DOI等字段🔄 如何优化爬虫稳定性与可扩展性。

2201_76125261的博客 415

C#文件夹基本操作(判断文件夹是否存在、创建文件夹、移动文件夹、删除文件夹以及遍历文件夹中的文件)

一、判断文件夹是否存在判断文件夹是否存在时,可以使用Directory类的Exists()方法或者DirectoryInfo类的Exists属性来实现。一、判断文件夹是否存在。

wenchm的博客 1万+

Python爬虫实战:利用Playwright与反反爬技术抓取Crunchbase企业数据

在当今数据驱动的商业环境中,获取准确的企业信息对于市场分析、竞争情报和投资决策至关重要。Crunchbase作为全球领先的企业信息平台,包含了数百万家公司、投资者和关键人员的详细数据。本文将深入探讨如何使用Python最新爬虫技术Playwright,结合多种反反爬策略,高效抓取Crunchbase企业数据。我们将从爬虫基础概念讲起,逐步深入到高级技巧,并提供完整的代码实现,帮助读者掌握现代网络数据采集的核心技术。网络爬虫技术自互联网诞生以来经历了显著演变。

2201_76125261的博客 1833

通信原理 | 通俗理解 | 因子图、消息传递以及它们之间的关系

在算法迭代过程中,通过反复更新这些消息,直到收敛,最终可以得到每个变量的边缘概率分布或最有可能的整体状态。算法通过因子图中的节点反复交换消息,直到找到最优解或所有消息稳定下来,从而解决了比如聚会日期这样的优化问题。在实际应用中,这种方法可以用来解决更复杂的问题,比如图像识别、语音识别和机器学习中的其他问题。,特别是在处理概率模型和执行概率推断时,因子图提供了一个强大的工具。(比如朋友的空闲时间和地点的可用性),并且你希望尽可能让所有人满意。在真正的因子图和消息传递算法中,这个过程被数学化和形式化。

若北辰 1197

C#语言中关于文件夹操作的功能

在C#语言中,文件夹操作通常通过System.IO命名控件中的类来实现。

qq_72607854的博客 1677

【人工智能之深度学习】21. 自动驾驶感知实战:YOLOv4复杂天气优化方案(BDD100K全代码+效果对比)

摘要:自动驾驶摄像头在雨雾天气下易受图像模糊、目标遮挡影响,导致YOLOv4检测精度骤降。本文基于BDD100K公开数据集(含多天气场景),设计三阶段优化方案:1)物理建模生成雨雾效果(雨滴线条+大气散射模型),将恶劣天气样本占比从20%提升至40%;2)在YOLOv4颈部嵌入CBAM注意力机制,强化模糊区域特征提取;3)L1剪枝(30%)+TensorRT量化实现轻量化。需特别说明:本文为教学虚拟案例,不可直接用于车载部署,实际落地需结合多传感器融合与ISO 26262认证。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 1686

DirectorySecurity & FileSystemAccessRule

http://developers.de/blogs/damir_dobric/archive/2007/06/18/directory-security-and-access-rules.aspx  设置文件夹权限时遇到的问题:1. 文件夹读写被拒绝但是文件还是可以读写: InheritanceFlags的使用, 见链接2. 拒绝比允许优先级高, 所以要remove掉之前的权

existch的专栏 972

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Asp.net给站点某目录增加Aspnet用户(转)

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.W...

congguijiang5851的博客 152

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Asp.net给站点某目录增加Aspnet用户

<!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--><script type="text/javascript"

zgqtxwd的专栏 377

【.NET开发者必看】:C#跨平台权限继承的7大最佳实践

解决C#跨平台开发中的权限管理难题,深入解析权限继承机制。涵盖多系统兼容策略、安全上下文传递与角色继承模式,提升应用安全性与维护效率。适用于微服务、桌面及移动跨平台场景,【.NET开发者必看】值得收藏

LogicGlow的博客 603

C#设置与获取目录权限(.net控制ACL)

C#设置与获取目录权限(.net控制ACL) 想用c#来设置和读取ntfs分区上的目录权限,找了很多资料,未果。终于发现了一段vb.net的代码,做了修改,以C#展示给大家。 using System; using System.Collections; using System.IO; using System.Security.AccessControl; stat

lingfengstar1的博客 852

QTVA-2015-198545、WooYun-2015-104148 .NET Framework Arbitrary File Permissions Modify Vul

catalog 1. Description 2. Effected Scope 3. Exploit Analysis 4. Principle Of Vulnerability 5. Patch Fix 1. Description 通过.NET Framework的这个API漏洞,攻击者可以赋予任意程序文件执行权限 Relevant Link: http:...

weixin_30396699的博客 162

c#设置目录权限(.net控制alc)

using System;using System.Collections;using System.IO;using System.Security.AccessControl;static class Tester{    public static void Main()    {        try        {            string filename = @"d:

wch_99的专栏 1468

C#创建文件夹并设置权限

/*需要添加以下命名空间:usingSystem.IO;usingSystem.Security.AccessControl;*/stringsPath=Server.MapPath(文件夹名称字符串);Directory.CreateDirectory(sPath);addpathPower(sPath,"ASPNET","FullCo...

weixin_30362801的博客 131

设置文件或文件夹权限

/// <summary> /// 为访问的文件分配权限 /// </summary> /// <param name="pathname">文件路径</param> /// <param name="username">赋予的username,类似"ASPNET"</param> //...

dianqianpang2137的博客 70
上一篇: jQuery Ajax之$.get()方法和$.post()方法
下一篇: C#编程实现访问系统文件夹的代码
ly_wolf
博客等级 码龄16年 9粉丝 5原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值