Share via


WebMatrix (Beta) appcmd.exe

What is it?

First, if you are unfamiliar with appcmd.exe, and what it can do for you, consider reading up on it here: https://learn.iis.net/page.aspx/114/getting-started-with-appcmdexe.  I've found that site fairly helpful in getting started with it.

What's it for?

appcmd.exe is a command-line tool that can manage EVERYTHING in IIS.  It has a much steeper learning curve than the UI for IIS, being a command-line tool, but it is quite powerful.

What does this have to do with WebMatrix?

Well, if there is something you can't find in the WebMatrix UI, chances are, it's possible to use the appcmd.exe that came with WebMatrix to do it.  The example I can think of is when you want to host something in WebMatrix on addresses other than localhost.  You may be hand-modifying applicationHost.config or using Microsoft.Web.Administration to add sites, or you're using the WebMatrix UI and adding sites from folders, but for whatever reason, localhost isn't what you want. 

Scenario: My site name is EchoService.  I want it to be hosted on http and https, but I want to be able to browse through the machine name, or ip address, or localhost, but not just localhost.  I need to open an admin command prompt and navigate to the WebMatrix installation folder.  In there, I'll find a copy of appcmd.  I run the following commands:

1. appcmd set site /site.name:EchoService /+bindings.[protocol='http',bindingInformation='*:12345:']

Here, "12345"
is the port that my site is getting hosted on by WebMatrix.  This command adds a site binding for http on port 12345.  But I better remove the existing entry that restricts it to localhost:

2. appcmd set site /site.name:EchoService /-bindings.[protocol='http',bindingInformation='*:12345
:localhost']

Notice that to remove a binding, we just use the minus sign.  Next, I want to add a site binding in the same way, but for https.  WebMatrix gave me port 44300 when I enabled ssl.  But it restricted me to localhost again, so...

3. appcmd set site /site.name:EchoService /+bindings.[protocol='https',bindingInformation='*:44300:']

Finally, I'll remove the existing entry for https that restricts to localhost:

4. appcmd set site /site.name:EchoService /-bindings.[protocol='https',bindingInformation='*:44300:localhost']

So, that's some examples of how to use appcmd to manage WebMatrix when the UI doesn't have what you need. Remember that WebMatrix is a lightweight website admin tool, unlike IIS, so you may come across a few things that don't appear to exist in WebMatrix. But keep in mind that WebMatrix has its own version of appcmd.exe to administer the sites. Of course, you could always hand-modify applicationHost.config. (In fact, hand-monitoring the applicationHost.config file as you execute these commands is a great way to validate that it worked.)