Hi in this article you can find relevant code to restart application pool from Asp.net
Restart IIS application pool from ASP.NET page
using System;
using System.Web;
using System.Web.UI;
using System.Management;
using System.DirectoryServices;
using System.Web.UI.WebControls;
public partial class iis : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(System.Environment.MachineName);
status();
}
protected void status()
{
string appPoolName = "dev.somesite.com";
string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName;
int intStatus = 0;
try
{
DirectoryEntry w3svc = new DirectoryEntry(appPoolPath);
intStatus = (int)w3svc.InvokeGet("AppPoolState");
switch (intStatus)
{
case 2:
lblStatus.Text = "Running";
break;
case 4:
lblStatus.Text = "Stopped";
break;
default:
lblStatus.Text = "Unknown";
break;
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
protected void stopAppPool(object sender, EventArgs e)
{
Button btn = (Button)sender;
string appPoolName = btn.CommandArgument;
string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName;
try
{
DirectoryEntry w3svc = new DirectoryEntry(appPoolPath);
w3svc.Invoke("Stop", null);
status();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
protected void startAppPool(object sender, EventArgs e)
{
Button btn = (Button)sender;
string appPoolName = btn.CommandArgument;
string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName;
try
{
DirectoryEntry w3svc = new DirectoryEntry(appPoolPath);
w3svc.Invoke("Start", null);
status();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}