I am trying to use IIS's appcmd
to programatically do the equivalent of the following in the IIS Manager application (inetmgr.exe
):
- In the
Connections
sidebar on the left, expand toHOSTNAME -> Sites
- Right-click
Default Web Site
and clickAdd application...
from the context menu. - The
Add Application
dialog will display- In the
Alias:
textbox typepath1/path2
- In the
Physical Path:
textbox typeC:\path1\path2
- Click
OK
- In the
- This will cause the app to be displayed in the
Connections
left sidebar under the pathHOSTNAME -> Sites -> Default Web Site -> path1 -> path 2
- Restarting IIS will cause
http://[::1]/path1/path2
to display the application, assuming it's bound to just[::1]
.
Here is what I have so far to do this programmatically:
# Copy my web.config file for my new site.
copy C:\test\web.config C:\path1\path2\web.config
C:\windows\system32\inetsrv\appcmd add app /site.name:"Default Web Site" /path:path1\path2
C:\windows\system32\inetsrv\appcmd vdir /app.name:"Default Web Site/path1/path2" /path:/ /physicalPath:C:\path1\path2
But after restarting IIS, it never displays in the Connections
left sidebar and I can't get to my application either.
However, I can list it using appcmd
:
C:\Windows\System32\inetsrv\appcmd list app
...
APP "Default Web Site/windows/gp" (applicationPool:DefaultAppPool)
...
C:\Windows\System32\inetsrv\appcmd list vdir
...
VDIR "Default Web Site/windows/gp/" (physicalPath:C:\path1\path2)
...
What else do I have to do? There's /commit
command in appcmd
but I don't understand what it does apart from editing an xml .config
on the
fly at some level...where are my changes?