【发布时间】:2011-07-07 00:36:02
【问题描述】:
我正在构建一个 ASP.NET 应用程序,它将在服务器上创建 Windows 帐户和组,并为这些帐户设置文件/文件夹权限。
我该如何做到这一点?
我曾考虑过使用 CACLS.exe,但我有一种感觉,最终会让我陷入其他问题。 .NET 框架中还有其他选项吗?
【问题讨论】:
标签: c# asp.net .net file-permissions
我正在构建一个 ASP.NET 应用程序,它将在服务器上创建 Windows 帐户和组,并为这些帐户设置文件/文件夹权限。
我该如何做到这一点?
我曾考虑过使用 CACLS.exe,但我有一种感觉,最终会让我陷入其他问题。 .NET 框架中还有其他选项吗?
【问题讨论】:
标签: c# asp.net .net file-permissions
我实现类似目标的一种方式。这就是某些操作或进程需要管理权限的地方,而您尝试通过 ASP.NET 执行此操作的目的是构建 WCF 服务应用程序(理想情况下作为自托管服务)并使其以管理员身份运行。
然后从您的 ASP.NET 应用程序中调用服务中的方法并且它可以工作。
编辑
这是使控制台应用程序成为 WCF 自托管应用程序的代码
class Program
{
static void Main(string[] args)
{
var webServiceHhost = new WebServiceHost(typeof(AppCmdService), new Uri("http://localhost:7654"));
ServiceEndpoint ep = webServiceHhost.AddServiceEndpoint(typeof(AppCmdService), new WebHttpBinding(), "");
var serviceDebugBehavior = webServiceHhost.Description.Behaviors.Find<ServiceDebugBehavior>();
serviceDebugBehavior.HttpHelpPageEnabled = false;
webServiceHhost.Open();
Console.WriteLine("Service is running");
Console.WriteLine("Press enter to quit ");
Console.ReadLine();
webServiceHhost.Close();
}
}
上面代码清单中的类AppCmdService是我的WCF服务类
【讨论】:
看来我要找的是System.DirectoryServices.AccountManagement Namespace。我将把它很好地包装在 WCF 服务中(谢谢,Shiv Kumar)并从我的应用程序中调用它。
【讨论】: