Can you please give me the code so that i can write in button click
Thanking You
protected void btnRestartAppPool_Click(object sender, EventArgs e)
{
var manager = new ServerManager();
var appPool = manager.ApplicationPools["Your_AppPool_Name"];
appPool.Stop();
appPool.Start();
}
P.S. don't forget to install Microsoft.Web.Administration from the NuGet (right-click the project and select
Manage NuGet Packages from the context menu) and then add the
using directive for Microsoft.Web.Administration. Voila!
Buddy you don't even try to do something by yourself. Please be aware that this is not a place where we write code for you. Rather, we provide help after you have given your best. Have you?
OK I cannot guarantee that the following will work as I am not sure if the wanted attribute name is correct (You may want to google the attributes list). Anyway here we go
ServerManager manager = new ServerManager();
var appPool = manager.ApplicationPools["Your_AppPool_Name"];
if(appPool != null)
{
if(appPool.State == ObjectState.Started)
{
// latest recycle time
Response.Write(appPool.GetAttribute("StartTime").Value + "<br />");
appPool.Stop();
appPool.Start();
// minutes since the last recycle (should be zero if the code works)
Response.Write(appPool.Recycling.PeriodicRestart.Time.TotalMinutes);
}
}
Note: You need to publish your application to iis, and then test.
ServerManager serverManager = new ServerManager();
ApplicationPool appPool = serverManager.ApplicationPools["applicationpool name"];
if (appPool != null)
{
if (appPool.State == ObjectState.Stopped)
{
appPool.Start();
}
else
{
appPool.Recycle();
}
}
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
294 Points
679 Posts
How To Restart Application Pool Using Asp.net button
Jul 21, 2020 09:07 AM|Gopi.MCA|LINK
Hello
Is that any code which restart application pool using asp.net button click?
Thanking You
All-Star
48570 Points
18081 Posts
Re: How To Restart Application Pool Using Asp.net button
Jul 21, 2020 09:43 AM|PatriceSc|LINK
Hi,
Either using the proper management classes such as https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.administration.applicationpool?view=iis-dotnet (may require extra permissions ?) or indirectly by doing something triggering the restart.
If I ever do that it would be rather in a separate application rather then embedded into the app itself.
Contributor
4232 Points
1147 Posts
Re: How To Restart Application Pool Using Asp.net button
Jul 21, 2020 09:44 AM|Kulrom|LINK
You can use WMI methods ApplicationPool.Stop and ApplicationPool.Start (calling them one after another) to restart the app pool
Also you could use the ServerManager Class (Microsoft.Web.Administration) which is very easy to use
My website: ASP.NET Custom Software Development
Member
294 Points
679 Posts
Re: How To Restart Application Pool Using Asp.net button
Jul 21, 2020 09:50 AM|Gopi.MCA|LINK
Hello
Thanks for your reply
Can you please give me the code so that i can write in button click
Thanking You
Contributor
4232 Points
1147 Posts
Re: How To Restart Application Pool Using Asp.net button
Jul 21, 2020 09:56 AM|Kulrom|LINK
P.S. don't forget to install Microsoft.Web.Administration from the NuGet (right-click the project and select Manage NuGet Packages from the context menu) and then add the using directive for Microsoft.Web.Administration. Voila!
HTH
My website: ASP.NET Custom Software Development
Member
294 Points
679 Posts
Re: How To Restart Application Pool Using Asp.net button
Jul 21, 2020 10:10 AM|Gopi.MCA|LINK
hello
how to check is that code is working or not
sp_configure can show result or have to see other ways
for older version how would be this var
Contributor
4232 Points
1147 Posts
Re: How To Restart Application Pool Using Asp.net button
Jul 21, 2020 11:03 AM|Kulrom|LINK
Buddy you don't even try to do something by yourself. Please be aware that this is not a place where we write code for you. Rather, we provide help after you have given your best. Have you?
OK I cannot guarantee that the following will work as I am not sure if the wanted attribute name is correct (You may want to google the attributes list). Anyway here we go
My website: ASP.NET Custom Software Development
Contributor
3370 Points
1409 Posts
Re: How To Restart Application Pool Using Asp.net button
Jul 22, 2020 03:22 AM|samwu|LINK
Hi Gopi.MCA,
You can also try use ApplicationPool.Recycle Method to restart application pool.
Note: You need to publish your application to iis, and then test.
Best regards,
Sam