如何使用.NET设置文件夹权限?

发布于 2024-08-21 18:59:36 字数 140 浏览 5 评论 0 原文

是否可以使用小型 .NET 页面来设置其所在服务器上某些文件夹的文件夹权限?可用于此目的的代码或对象是什么?我使用的是 Windows Server 2003。

基本上,我想使用 GET 或 POST 访问页面并让它运行并检查和/或更新文件夹的权限。

Is it possible to use a small .NET page to set folder permissions on some folders on the server where it resides? What is the code or objects that can be used for this? I am on Windows Server 2003.

Basically I want to hit the page with a GET or POST and have it run and check and/or update the permissions on a folder.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尾戒 2024-08-28 18:59:36

有多种可能的方法可以解决这个问题。

一种是使用 FileIOPermissions 类,该类允许您指定文件和文件夹的权限。

另一种选择是使用 DirectorySecurity 类在 System.Security.AccessControl 命名空间内,特别是该类的 SetAccessControl 方法。

第二种方法应该为您提供更精细的权限设置和控制,因为 System.Security.AccessControl 命名空间允许您以编程方式创建或修改 用于许多受保护资源(例如文件、文件夹等)的自主访问控制列表 (DACL) 和系统访问控制列表 (SACL)

无论您选择哪种方法来执行权限设置,您都需要注意运行 ASP.NET 驱动代码的帐户。您说您使用的是 Windows Server 2003,因此您可能使用 IIS 版本 6.0< /a>.默认情况下,IIS 6.0 将运行“ 下的所有用户代码Network Service”帐户,这是一个低权限帐户,在 IIS 进程和网站层次结构之外具有有限的权限。您可以阅读 MSDN 文章“如何:使用网络服务帐户访问资源”在 ASP.NET 中” 有关访问服务器端资源以及您在此帐户下将拥有的具体访问权限的信息。

根据您想要执行的操作的具体性质,您可能还需要查看 ASP.NET 模拟,使您的服务器端代码能够在不同帐户的上下文中运行。请参阅 MSDN 文章“如何:在 ASP.NET 2.0 中使用模拟和委派< /a>”了解更多信息。

There's a number of possible ways to approach this.

One is to use the FileIOPermissions class, which allows you to specify permissions on files and folders.

The other option is to use the DirectorySecurity class within the System.Security.AccessControl Namespace, and specifically the SetAccessControl Method of that class.

This second method should provide you with much more granularity and control over the setting of permissions as the System.Security.AccessControl namespace allows you to programmatically create or modify discretionary access control lists (DACLs) and system access control lists (SACLs) for a number of protected resources such as files, folders, and so on.

Irrespective of the method you choose to perform the permission setting, you will need to be mindful of the account that your ASP.NET-driven code is running under. You say you are using Windows Server 2003, so you're probably using IIS version 6.0. By default, IIS 6.0 will run all user code under the "Network Service" account, which is a low-privilege account and will have limited permissions outside of the IIS processes and the website hierarchy. You can read the MSDN article, "How To: Use the Network Service Account to Access Resources in ASP.NET" regarding accessing resources on the server side and exactly what access you will have under this account.

Depending upon the exact nature of what you want to do, you may also need to look into ASP.NET Impersonation to enable your server side code to run under the context of a different account. See the MSDN article, "How To: Use Impersonation and Delegation in ASP.NET 2.0" for more information on that.

め七分饶幸 2024-08-28 18:59:36

您可以使用 FileIOPermission 类来执行此操作这。只需确保运行网站的用户具有执行所有安全设置的权限即可。

You can use the FileIOPermission class to do this. Just make sure the user under which the website is running has this permission to do all the security settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文