I am trying to use IIS'sappcmdto programatically do the equivalent of the following in the IIS Manager application (inetmgr.exe):
In theConnectionssidebar on the left, expand toHOSTNAME -> Sites
Right-clickDefault Web Siteand clickAdd application...from the context menu.
TheAdd Applicationdialog will display
In theAlias:textbox typepath1/path2
In thePhysical Path:textbox typeC:\path1\path2
ClickOK
This will cause the app to be displayed in theConnectionsleft sidebar under the pathHOSTNAME -> Sites -> Default Web Site -> path1 -> path 2
Restarting IIS will causehttp://[::1]/path1/path2to 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 theConnectionsleft sidebar and I can't get to my application either.
However, I can list it usingappcmd:
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/commitcommand inappcmdbut I don't understand what it does apart from editing an xml.configon the
fly at some level...where are my changes?
But after restarting IIS, it never displays in theConnectionsleft sidebar and I can't get to my application either.
Before restarting iis, is there a website you created with appcmd in your Connections?
Please check if the website you created exists in applicationHost.config.
The file is located at: %windir%\System32\inetsrv\config\applicationHost.config
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Sure it's listed, I added an app to the Default Website, not a website; you can see it here:
I suggest you recreate the site in appcmd for testing, and then don’t name it Default WebSite.
Normally, there will be a default website in applicationHost.config named Default Web Site, It is possible that your website was not created successfully.
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
3 Posts
Programmatically adding vdir and app using appcmd in IIS?
Dec 05, 2020 06:44 PM|helpdeskaleer|LINK
I am trying to use IIS's
appcmd
to programatically do the equivalent of the following in the IIS Manager application (inetmgr.exe
):Connections
sidebar on the left, expand toHOSTNAME -> Sites
Default Web Site
and clickAdd application...
from the context menu.Add Application
dialog will displayAlias:
textbox typepath1/path2
Physical Path:
textbox typeC:\path1\path2
OK
Connections
left sidebar under the pathHOSTNAME -> Sites -> Default Web Site -> path1 -> path 2
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:
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
:What else do I have to do? There's
/commit
command inappcmd
but I don't understand what it does apart from editing an xml.config
on the fly at some level...where are my changes?90 Posts
Re: Programmatically adding vdir and app using appcmd in IIS?
Dec 07, 2020 08:53 AM|samwu|LINK
Hi helpdeskaleer,
Before restarting iis, is there a website you created with appcmd in your Connections?
Please check if the website you created exists in applicationHost.config.
The file is located at: %windir%\System32\inetsrv\config\applicationHost.config
Best regards,
Sam
3 Posts
Re: Programmatically adding vdir and app using appcmd in IIS?
Dec 07, 2020 07:22 PM|helpdeskaleer|LINK
Sure it's listed, I added an app to the Default Website, not a website; you can see it here:
https://imgur.com/ku427Cqhttps://imgur.com/ku427Cq
3 Posts
Re: Programmatically adding vdir and app using appcmd in IIS?
Dec 07, 2020 07:33 PM|helpdeskaleer|LINK
See comments <!-- --> below:
...
<sites>
<site name="Default Web Site" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
</application>
<!-- BEGIN: These were added by the GUI (and display, see screenshot) -->
<application path="/MyApp" applicationPool="DefaultAppPool">
<virtualDirectory path="/" physicalPath="C:\meWikis" />
</application>
<application path="/Simphony" applicationPool="DefaultAppPool">
<virtualDirectory path="/" physicalPath="C:\SimphWiki" />
</application>
<application path="/Simphony/emc" applicationPool="DefaultAppPool">
<virtualDirectory path="/" physicalPath="C:\Simphony_EMC" />
</application>
<application path="/CasinoLicenses" applicationPool="DefaultAppPool">
<virtualDirectory path="/" physicalPath="C:\CasinoLicenses" />
</application>
<!-- END: These were added by the GUI (and display, see screenshot) -->
<!-- BEGIN: These were added by the AppCMD (but does not display, see screenshot) -->
<!-- However it does work...go figure... -->
<application path="/windows/gp">
<virtualDirectory path="/" physicalPath="C:\tw5\windows\gp" />
</application>
<!-- END: These were added by the AppCMD (but does not display, see screenshot) -->
<bindings>
<binding protocol="http" bindingInformation="[::1]:80:" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%SystemDrive%\inetpub\logs\LogFiles" />
<traceFailedRequestsLogging directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles" />
</siteDefaults>
<applicationDefaults applicationPool="DefaultAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
90 Posts
Re: Programmatically adding vdir and app using appcmd in IIS?
Dec 08, 2020 09:33 AM|samwu|LINK
Hi helpdeskaleer,
I suggest you recreate the site in appcmd for testing, and then don’t name it Default WebSite.
Normally, there will be a default website in applicationHost.config named Default Web Site, It is possible that your website was not created successfully.
Best regards,
Sam