简体   繁体   中英

Create Windows accounts and set file permissions from ASP.NET site

I'm building an ASP.NET application, which will create Windows accounts and groups on the server, and set file/folder permissions for those accounts.

How do I accomplish that?

I've considered shelling out to CACLS.exe, but I got a feeling that's going to get me into other problems eventually. Are there any other options in the .NET framework?

One way in which I've achieved something similar. That is where some operation or process requires administrative privileges and you're trying to do this via ASP.NET is to build a WCF service application (ideally as a self hosted service) and have it running as Administrator.

Then from your ASP.NET application you call methods in your service and it works.

EDIT

Here is the code to make a console application a WCF self hosted application

  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(); 
    }
  }

The class AppCmdService in the code listing above is my WCF service class

It seems it's the System.DirectoryServices.AccountManagement Namespace I'm looking for. I'm going to wrap that up nicely in a WCF service (thanks, Shiv Kumar ) and call that from my app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM