Restarting a website from its web page

Well, just to make it simple: I have a web form. On it is the "Restart" button. I click on this button and IIS will restart.

Now, what will be the C # code that I will need to write behind the OnClick event of this web button? (If possible?)


Then a second button is added. It is called "Reset" and should just reset the AppDomain for the current web application. What will be the code for this?
+3
source share
4 answers
protected void Reload_Click(object sender, EventArgs e)
{
    HttpRuntime.UnloadAppDomain();
}

protected void Restart_Click(object sender, EventArgs e)
{
    using (var sc = new System.ServiceProcess.ServiceController("IISAdmin"))
    {
        sc.Stop();
        sc.Start();
    }
}
+11
source
Process iisreset = new Process();
iisreset.StartInfo.FileName   = "iisreset.exe";
iisreset.StartInfo.Arguments = "computer name";
iisreset.Start();

//iisreset.exe is located in the windows\system32 folder.
+3
source

(http://www.velocityreviews.com/forums/t300488-how-can-i-restart-iis-or-server-from-aspx-page-or-web-service.html)

string processName = "aspnet_wp";

System.OperatingSystem os = System.Environment.OSVersion;

//Longhorn and Windows Server 2003 use w3wp.exe
if((os.Version.Major == 5 && os.Version.Minor > 1) || os.Version.Major ==6)
   processName = "w3wp";

foreach(Process process in Process.GetProcessesByName(processName))
   {
      Response.Write("Killing ASP.NET worker process (Process ID:" +
      process.Id + ")");
      process.Kill();
   }
+1

Is there more than one website hosted on a server that will run this code? If so, you can look at the System.DirectoryServices namespace and restart a separate website

+1
source

Source: https://habr.com/ru/post/1712541/


All Articles