Freigeben über


IIS AppCmd Quick Reference

IIS appcmd is very handy for deployment automation of .NET web applications. The appcmd can be found at %systemroot%\system32\inetsrv or %systemroot%\\SysWOW64\inetsrv on web server. Please refer to IIS Administration Tools for details. The following is a quick reference for the most common usages of appcmd in web application deployment automation.

1. Add Site
appcmd add site /name:MySite /bindings:https://*:80 /physicalpath:”d:\MySitePath”
2. Add App Pool
appcmd add apppool /name:MyAppPool /managedRuntimeVersion:v4.0 (e.g. targeting .NET 4.0)
3. Set App Pool Credential
appcmd set config /section:applicationPools /[name='MyAppPool'].processModel.identityType:SpecificUser /[name='MyAppPool'].processModel.userName:MyDomain\MyAccount /[name='MyAppPool'].processModel.password:MyAccountPassword
4.Add App
appcmd add app /site.name:"MySite" /path:/MyApp /physicalpath:"d:\MySitePath\MyApp"
5. Assign/Change App Pool to an App
appcmd set app "MySite/MyApp" /applicationpool:MyAppPool
6. List (App, Site, AppPool, etc.)
appcmd list app
appcmd list site
appcmd list apppool
7. Enable/Disable Anonymous Authentication (True to Enable, False to Disable)
appcmd set config "MySite/MyApp" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"True" /commit:apphost
8. Enable Windows Authentication (True to Enable, False to Disable)
appcmd.exe set config "MySite/MyApp" -section:system.webServer/security/authentication/windowsAuthentication /enabled:"True" /commit:apphost
9. Change Windows Authentication Providers (NTLM or Negotiate)
appcmd set config MySite/MyApp -section:system.webServer/security/authentication/windowsAuthentication /~providers /commit:apphost (clear provider list)
appcmd set config MySite/MyApp -section:system.webServer/security/authentication/windowsAuthentication /-providers.[value='NTLM'] /commit:apphost (set to NTLM)
appcmd set config MySite/MyApp -section:system.webServer/security/authentication/windowsAuthentication /+providers.[value='Negotiate'] /commit:apphost (set to Negotiate)
10. Add Custom Header – for example, nosniff header or IE 7 compatiable header
appcmd set config MySite -section:system.webServer/httpProtocol /+customHeaders.[name='X-Content-Type-Options',value='nosniff'] /commit:apphost
appcmd set config MySite -section:system.webServer/httpProtocol /+customHeaders.[name='X-UA-Compatible',value='IE=EmulateIE7'] /commit:apphost
11. Add Default Document - error if it exists already
appcmd set config "MySite/MyApp" /section:defaultDocument /+files.[value='default.asmx']
12. Delete App and Site - error if it doesn’t exist
appcmd delete app "MySite/MyApp"
appcmd delete site "MySite"
13. Delete AppPool- error if it doesn’t exist or it is used by app
appcmd delete apppool MyAppPool
14. Backup and Restore IIS Settings
appcmd add backup MyBackup
appcmd restore backup MyBackup
15. HTTPS Binding if you are using HTTP over SSL
appcmd set site /site.name:"MyApp" /+bindings.[protocol='https',bindingInformation='*:443:MySSLCertificate']

Comments

  • Anonymous
    August 29, 2013
    The comment has been removed

  • Anonymous
    July 02, 2014
    Excellent. I was spending more time to get all these commands from various sites. Your blog helps a lot. Thanks, Sundaresan.

  • Anonymous
    January 08, 2015
    Is there a command add sever name to recycle app pool remotely?

  • Anonymous
    February 23, 2015
    Thanks for posting this command list. Please add more

  • Anonymous
    September 28, 2015
    The comment has been removed