When managing IIS7+ websites, four operations often cause confusion:
# Command line example
iisreset /stop
iisreset /start
This command completely stops and restarts all IIS services (W3SVC, WAS, and dependent services). Impact:
- Drops all active connections
- Clears in-memory session state
- Requires admin privileges
# Graceful restart with timeout
iisreset /restart /timeout:30
More surgical than iisreset, recycling:
- Creates new worker process (w3wp.exe)
- Maintains existing process until new one initializes
- Preserves HTTP.SYS request queue
Common PowerShell automation:
Import-Module WebAdministration
Restart-WebAppPool -Name "MyAppPool"
Operation | Effect | Typical Use Case |
---|---|---|
Restart | Terminates active connections, forces full reinitialization | Configuration changes requiring clean state |
Refresh | Reloads configuration without interrupting service | Updating bindings or physical path changes |
Benchmark results (1000 concurrent users):
- iisreset: 8-12 seconds downtime
- Recycle: 2-5 seconds latency spike
- Restart: 3-7 seconds interruption
- Refresh: <1 second blip
Memory leak: Scheduled recycling (2-3 times daily)
Config error: Restart for full reload
Certificate update: Refresh suffices
# Monitoring script
while ($true) {
Get-Process w3wp | Select-Object WS,CPU
Start-Sleep -Seconds 5
}
When managing IIS7, these four operations have distinct behaviors that affect web applications differently:
// Example PowerShell command for iisreset
iisreset /noforce
iisreset completely stops and restarts all IIS services (W3SVC, WAS, and related components). This affects all websites on the server:
- Terminates all active connections
- Clears in-memory sessions and application state
- Requires administrator privileges
Recycling an app pool maintains availability through overlapped processing:
// C# code to recycle programmatically
using (ServerManager serverManager = new ServerManager())
{
ApplicationPool pool = serverManager.ApplicationPools["MyAppPool"];
pool.Recycle();
}
Key characteristics:
- New worker process starts before old one terminates
- Existing requests complete on old process
- Application state preserved if configured properly
Operation | Scope | Impact |
---|---|---|
Restart | Entire website | Drops active connections |
Refresh | Configuration only | No connection interruption |
When to use each:
- After GAC assembly updates → iisreset
- Memory leak mitigation → Scheduled recycling
- Config file changes → Refresh
- SSL certificate updates → Website restart
# Batch script for safe recycling
@echo off
echo Stopping AppPool...
%windir%\system32\inetsrv\appcmd stop apppool /apppool.name:MyAppPool
timeout /t 5
echo Starting AppPool...
%windir%\system32\inetsrv\appcmd start apppool /apppool.name:MyAppPool
The key difference lies in the scope and disruption level - choose based on your specific maintenance requirements.