I am using ASP.NET Razor Template to create a web app, that i can use to start and stop services through. I have a text box,in which i can feed in service and a Start and Stop button
<div>
<form>
Service Name:<br>
<input type="text" name="servicename"><br>
<button onclick=@Model.StartService("servicename")>Start</button> <button onclick=@Model.StopService("servicename")>Start</button>
</form>
</div>
I have a Model that has the stop and Start service Method that takes in the service name as the argument. Running my app automaically calls the StartService and StopService. I want them to be invoked only when the button is clicked
Here is my model
public string StopService(string serviceName)
{
ServiceController[] controller = ServiceController.GetServices(serviceName);
if (controller == null)
{
return null;
}
controller[0].Stop();
controller[0].WaitForStatus(ServiceControllerStatus.Stopped);
return controller[0].Status.ToString();
}
public string StartService(string serviceName)
{
ServiceController[] controller = ServiceController.GetServices(serviceName);
if (controller == null)
{
return null ;
}
controller[0].Start();
controller[0].WaitForStatus(ServiceControllerStatus.Running);
return controller[0].Status.ToString();
}
I could be doing it all wrong but i am very new to this. I want to achieve this through the suggested the web template (ie., using Razor Page)