Publish Website On IIS Using AppCmd

Introduction

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.

Description

I assume you are aware of (or have knowledge of) how to Host or Publish a Website in IIS using Inetmgr. This will help you understand AppCmd.exe.

AppCmd.exe is the command line tool for managing IIS 7 and above. It provides an easy way to manage a website without Graphical User Interface.

Some of the things you can do with AppCmd,

  • Create and configure sites, apps, application pools, and virtual directories
  • Start and stop sites, and recycle application pools
  • Search, manipulate, export, and import IIS and ASP.NET configuration

How to Use AppCmd.exe?

The AppCmd.exe command line is built on top of a set of top-level server management objects, such as Site and Application. These objects expose methods that can be used to perform various actions on those objects, and object instances expose properties that can be inspected and manipulated.

AppCmd.exe is located in the %systemroot%\system32\inetsrv\ directory. Because it is not a path of the PATH automatically, you need to use the full path to the executable when executing commands like in %systemroot%\system32\inetsrv\AppCmd.exe list sites. Alternatively, you can manually add the inetsrv directory to the path on your machine so that you can access AppCmd.exe directly from any location.

Note. Run Command Prompt as Administrator using AppCmd.

In this article, we learn basic commands to host websites.

List all available commands and actions in AppCmd

AppCmd
or
AppCmd /?

AppCmd

From the above screenshot, it is clear that Command Prompt is run as administrator and run AppCmd which returns a list of supported commands.

List all hosted or published websites in IIS

AppCmd List Site

Websites

In the above screenshot, I have run the List Site command which returns all published sites with bindings and the state of the site e.g. Started or Stop.

Create the website using AppCMD

APPCMD add site /name:WebByAppCMD /bindings:"http/*:94:" /physicalPath:"C:\Users\Mepani\Desktop\2018 Article\Kendo Grid" -virtualDirectoryDefaults.userName:USERNAME -virtualDirectoryDefaults.password:PASSWORD

For any website hosting we require information as above like Site Name, Bindings (Protocol, hostname), Physical Path, Credential for access, or permission to folder path.

Sometimes, if you don't provide access/permission to a physical path then you might be getting an Access denied error.

View Newly Hosted or published website

appcmd.exe list site "WEbByAppCMD"  

Start and stop hosting or publishing a website

appcmd.exe start site "WEbByAppCMD"
appcmd.exe stop site "WEbByAppCMD"

Delete or remove published or hosted websites from IIS

appcmd.exe delete site "WEbByAppCMD"

Grid Demo

In the above screenshot, we have covered all the above site commands except delete. Possible issues or challenges that might be faced during command-line website hosting include.

  • The site name has already been created
  • The Port is already in use
  • Bad Request -Invalid hostname

Reference link

Hope you enjoyed this and learned a new way to host or publish a website using AppCmd.

Conclusion

In this article, we have learned about the command line tool AppCmd to manage a website in IIS with fewer easy commands.