I have a site where I need to restart the site and its apppool each time I make changes. When I'm debugging one of the scripts it becomes a chore to do it manually each time (it's 5-6 clicks).
Is there a way to automate it in a batch file?
Edit: I found how to restart the apppool from https://stackoverflow.com/a/38607626/492336, but I need to restart the site as well:
C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:"MYAPPPOOLNAME"
When you restart IIS, all session connected to web server are dropped. Any data held in web applications is lost. All Internet sites are unavailable until Internet services are restarted. So Microsoft suggest users avoid restarting, stopping, or rebooting server if at all possible.
Does IISRESET recycle the application pools? The correct answer is no. Instead, IISRESET causes the shutdown of all active IIS worker processes, kills them if they do not stop in time.
After some searching and trial and error, I came up with a short script, where "Default Web Site" is the name of the site to restart:
C:\Windows\System32\inetsrv\appcmd stop apppool /apppool.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd stop site /site.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd start site /site.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:"Default Web Site"
If you get this error:
message:The WAS service is not available - try starting the service first.
Try to execute with admin privileges.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With