Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The solution I use for this sort of thing (Where you're trying to run a process from ASP.NET that needs administrative privileges) is the following:</p> <ol> <li>Write whatever you need done as a Self hosted WCF service. Preferably an Http REST Service, so it's easy to call (even using just a browser for testing)</li> <li>Make sure you service is run using an administrator account. You can use the task scheduler to make sure the service is running at all times as well as run using an Administrator account.</li> <li>Execute methods on the service from your ASP.NET application using a WCF Client</li> </ol> <p>And it works all the time no matter what "process" I'm trying to run from within an ASP.NET application.</p> <p>Now as far are the details (code) is concerned let me know if you need help. The code below is the code you'd have in a console application in order to make it a self hosted WCF Service.</p> <p>In this case it's an Http service listening on port 7654.</p> <pre><code>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&lt;ServiceDebugBehavior&gt;(); serviceDebugBehavior.HttpHelpPageEnabled = false; webServiceHhost.Open(); Console.WriteLine("Service is running"); Console.WriteLine("Press enter to quit "); Console.ReadLine(); webServiceHhost.Close(); } </code></pre> <p>AppCmdService is a WCF Service class that looks like this (in my case). In your case you probably don't need a response from your service. In my case I'm getting a Json response. The actual implementation of what it is you're trying to do will be different obviously. But I'm assuming you already have that piece worked out. So simply call a method of that class from here.</p> <pre><code> [ServiceContract] public class AppCmdService { [WebGet(UriTemplate = "/GetCurrentExcutingRequests/?", ResponseFormat= WebMessageFormat.Json)] [OperationContract] public IEnumerable&lt;ExecutingRequestJson&gt; GetCurrentExcutingRequests() { return CurrentExecutingRequestJsonProvider.GetCurrentExecutingRequests("localhost"); } } </code></pre> <p>On your ASP.NET side, you don't really need a WCF client. All you need is a way to make an http call to the service. So you can simply use HttpWebRequest to make the call out to your service, which in turn execute your process.</p> <p>Hope all of this makes sense?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload