In this article, we will learn the most useful and powerful command-line tool, AppCmd, for publishing or hosting a website on IIS. Using the AppCmd tool, we can host static as well as a dynamic website (ASP.NET Webform, MVC, Dot Net Core etc) easily. The appcmd can be found at c:\Windows\System32\inetsrv on a web server.
List all commands:
List all available commands and actions in AppCmd. As per screenshot, it is clear that Command Prompt is run as administrator and run AppCmd which return list of supported Command.
# AppCmd /?
List App, Site, AppPool, etc.:
List all hosted or published websites in IIS. In other words, use following command to display all the app and sites configure in your IIS Server.
# appcmd list app
# appcmd list site
# appcmd list apppool
List the new hosted or published websites using following command.
# appcmd list site "windows.techoism.net"
Start and Stop hosted Website:
Start and Stop hosted or published website.
# appcmd start site "windows.techoism.net"
# appcmd stop site "windows.techoism.net"
Enable/Disable Anonymous Authentication:
You can easily enable or disable the anonymous authentication. We use True to Enable and False to Disable the authentication.
# appcmd set config "windows.techoism.net" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"True" /commit:techpool
Enable Windows Authentication:
Same as anonymous authentication we can also enable or disable the windows authentication for the website. We use True to Enable and False to Disable the authentication.
# appcmd set config "windows.techoism.net" -section:system.webServer/security/authentication/windowsAuthentication /enabled:"True" /commit:techpool
Change Windows Authentication Providers:
You can also change the windows authentication to NTLM or Negotiate using following commands.
Clear Provider List:
# appcmd set config windows.techoism.net -section:system.webServer/security/authentication/windowsAuthentication /~providers /commit:techpool
For NTLM Authentication:
# # appcmd set config windows.techoism.net -section:system.webServer/security/authentication/windowsAuthentication /+providers.[value='NTLM'] /commit:techpool
For Negotiate Authentication:
# appcmd set config windows.techoism.net -section:system.webServer/security/authentication/windowsAuthentication /+providers.[value='Negotiate'] /commit:techpool
Add Custom Header:
You can also add the custom header using the following commands. For example, nosniff header or IE 7 compatible header
# appcmd set config windows.techoism.net -section:system.webServer/httpProtocol /+customHeaders.[name='X-Content-Type-Options',value='nosniff'] /commit:techpool
For IE 7 Compatible Header:
# appcmd set config windows.techoism.net -section:system.webServer/httpProtocol /+customHeaders.[name='X-UA-Compatible',value='IE=EmulateIE7'] /commit:techpool
Add Default Document:
Add default document using the following command. If default document is already an exist then you will get an error.
# appcmd set config "windows.techoism.net" /section:defaultDocument /+files.[value='default.asmx']
Backup and Restore IIS Settings:
By using the following commands we can backup as well as restore the IIS setting.
# appcmd add backup MyTechIISBackup
# appcmd restore backup MyTechIISBackup
HTTPS is a secure communications channel that is used to exchange information between a client computer and a server. It uses Secure Sockets Layer (SSL). Use following command for binding website with HTTPS.
# appcmd set site /site.name:"windows.techoism.net" /+bindings.[protocol='https',bindingInformation='*:443:windows.techoism.net']
Delete the website using following command. If you received an error it’s means website doesn’t exist.
# appcmd delete site "windows.techoism.net"
Delete the apppool using following command. If you received an error it’s means website doesn’t exist or It’s used by app.