Programmatically adding vdir and app using appcmd in IIS?RSS

4 replies

Last post Dec 08, 2020 09:33 AM by samwu

  • 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):

    1. In the Connections sidebar on the left, expand to HOSTNAME -> Sites
    2. Right-click Default Web Site and click Add application... from the context menu.
    3. The Add Application dialog will display
      1. In the Alias: textbox type path1/path2
      2. In the Physical Path: textbox type C:\path1\path2
      3. Click OK
    4. This will cause the app to be displayed in the Connections left sidebar under the path HOSTNAME -> Sites -> Default Web Site -> path1 -> path 2
    5. 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?

  • Re: Programmatically adding vdir and app using appcmd in IIS?

    Dec 07, 2020 08:53 AM|samwu|LINK

    Hi helpdeskaleer,

    helpdeskaleer

    But after restarting IIS, it never displays in the Connections left 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.
  • 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 

  • 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>

  • Re: Programmatically adding vdir and app using appcmd in IIS?

    Dec 08, 2020 09:33 AM|samwu|LINK

    Hi helpdeskaleer,

    helpdeskaleer

    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.