appcmd IIS7/7.5 add Default Doc of type "remove" [Answered]RSS

10 replies

Last post Mar 22, 2011 11:43 PM by Leo Tang - MSFT

  • appcmd IIS7/7.5 add Default Doc of type "remove"

    Mar 17, 2011 05:48 AM|itisdesign|LINK

    The docs state:

    --------------------------------------------
    To add a file name to the list of default documents, use the following syntax:

    appcmd set config /section:defaultDocument /+files.[value=' string ']
    --------------------------------------------

    This only adds an "add" entry. (i.e. <add value="index.foo" />)

    I need to write these 2 lines (in case index.foo is already added at server level):
    <remove value="index.foo" />
    <add value="index.foo" />

    This post indicates IIS7.5 added ability to do this.  However, it does not discuss the syntax for default document.

    What is the syntax to add a "remove" entry? (i.e. <remove value="index.foo" />)

    Thanks!,
    -Aaron Neff

    appcmd IIS7 configuration iis7 configuration IIS 7 scripts applicationHost.config appcmd configuration IIS 7.0 web.config IIS 7.5 appcmd.exe 7.0 7.5 default document scripting Command line IIS 7 administration defaultDocument

  • Re: appcmd IIS7/7.5 add Default Doc of type "remove"

    Mar 17, 2011 06:35 AM|itisdesign|LINK

    Basically, I need to know how to add a removeElement to the files collection of the default document section.

    appcmd IIS7 configuration iis7 configuration IIS 7 scripts applicationHost.config appcmd configuration IIS 7.0 web.config IIS 7.5 appcmd.exe 7.0 7.5 default document scripting Command line IIS 7 administration defaultDocument

  • Re: appcmd IIS7/7.5 add Default Doc of type "remove"

    Mar 17, 2011 08:14 AM|itisdesign|LINK

    itisdesign

    The docs state:

    --------------------------------------------
    To add a file name to the list of default documents, use the following syntax:

    appcmd set config /section:defaultDocument /+files.[value=' string ']
    --------------------------------------------

    The following undocumented syntax also works, for adding an addElement: appcmd set config /section:defaultDocument /+files.add[value=' string ']

    But this syntax fails, for adding a removeElement: appcmd set config /section:defaultDocument /+files.remove[value=' string ']

    What gives?  Is it not possible to add a removeElement with appcmd?

    Thanks,
    -Aaron

    appcmd IIS7 configuration iis7 configuration IIS 7 scripts applicationHost.config appcmd configuration IIS 7.0 web.config IIS 7.5 appcmd.exe 7.0 7.5 default document scripting Command line IIS 7 administration defaultDocument

  • Re: appcmd IIS7/7.5 add Default Doc of type "remove"

    Mar 17, 2011 06:34 PM|itisdesign|LINK

    itisdesign


    This post indicates IIS7.5 added ability to do this.  However, it does not discuss the syntax for default document.

    That post also says:
    Appcmd now has ability to add <clear/> tag in the collections using ‘~’. Command to clear <error> collection entries in httpErrors section will be following.  appcmd set config /section:httpErrors /~

    So.. I tried the following on IIS 7.5:

    • <div mce_keep="true">appcmd set config /section:defaultDocument /~</div>
    • <div mce_keep="true"> <div mce_keep="true">appcmd set config /section:defaultDocument /files~</div></div>
    • <div mce_keep="true"> <div mce_keep="true"> <div mce_keep="true">appcmd set config /section:defaultDocument /files.~</div></div></div>
    • <div mce_keep="true"> <div mce_keep="true"> <div mce_keep="true"> <div mce_keep="true">appcmd set config /section:defaultDocument /files.[]~</div></div></div></div>
    • <div mce_keep="true"> <div mce_keep="true"> <div mce_keep="true"> <div mce_keep="true"> <div mce_keep="true">appcmd set config /section:defaultDocument /files.[value='index.foo']~</div></div></div></div></div>

    Nope.  They all failed to add a "clear" tag.

    1. <div mce_keep="true">Can appcmd add "remove" elements to the default document collection?</div>
    2. <div mce_keep="true">Can appcmd add "clear" elements to the default document collection?</div>

    I don't need to clear the config.  I just need to override the inheritance (preferably using "remove" tags, but I'd be willing to use a "clear"+"add" workaround - if it would actually work!)

    Thanks,
    -Aaron

  • Re: appcmd IIS7/7.5 add Default Doc of type "remove"

    Mar 17, 2011 06:47 PM|itisdesign|LINK

    itisdesign


    So.. I tried the following on IIS 7.5:
    • <div>appcmd set config /section:defaultDocument /~</div>
    • <div> <div>appcmd set config /section:defaultDocument /files~</div></div>
    • <div> <div> <div>appcmd set config /section:defaultDocument /files.~</div></div></div>
    • <div> <div> <div> <div>appcmd set config /section:defaultDocument /files.[]~</div></div></div></div>
    • <div> <div> <div> <div> <div>appcmd set config /section:defaultDocument /files.[value='index.foo']~</div></div></div></div></div>

    Nope.  They all failed to add a "clear" tag.

    I also tried the following on IIS 7.5:

    • <div>appcmd set config /section:defaultDocument /files /~</div>
    • <div> <div>appcmd set config /section:defaultDocument /files. /~</div></div>
    • <div> <div> <div>appcmd set config /section:defaultDocument /files.[] /~</div></div></div>
    • <div> <div> <div> <div>appcmd set config /section:defaultDocument /files.[value='index.foo'] /~</div></div></div></div>
    <div> <div> <div>All failed to add a "clear" tag.</div></div></div>
  • Re: appcmd IIS7/7.5 add Default Doc of type "remove"

    Mar 17, 2011 07:22 PM|itisdesign|LINK

    itisdesign


    itisdesign


    So.. I tried the following on IIS 7.5:
    • <div>appcmd set config /section:defaultDocument /~</div>
    • <div> <div>appcmd set config /section:defaultDocument /files~</div></div>
    • <div> <div> <div>appcmd set config /section:defaultDocument /files.~</div></div></div>
    • <div> <div> <div> <div>appcmd set config /section:defaultDocument /files.[]~</div></div></div></div>
    • <div> <div> <div> <div> <div>appcmd set config /section:defaultDocument /files.[value='index.foo']~</div></div></div></div></div>

    Nope.  They all failed to add a "clear" tag.

    I also tried the following on IIS 7.5:

    • <div>appcmd set config /section:defaultDocument /files /~</div>
    • <div> <div>appcmd set config /section:defaultDocument /files. /~</div></div>
    • <div> <div> <div>appcmd set config /section:defaultDocument /files.[] /~</div></div></div>
    • <div> <div> <div> <div>appcmd set config /section:defaultDocument /files.[value='index.foo'] /~</div></div></div></div>
    <div> <div> <div>All failed to add a "clear" tag.</div></div></div>

    I also tried the following on IIS 7.5:

    • <div>appcmd set config /section:defaultDocument /files/~</div>
    • <div> <div>appcmd set config /section:defaultDocument /files./~</div></div>
    • <div> <div> <div>appcmd set config /section:defaultDocument /files.[]/~</div></div></div>
    • <div> <div> <div> <div>appcmd set config /section:defaultDocument /files.[value='index.foo']/~</div></div></div></div>
    <div> <div> <div>All also failed to add a "clear" tag.</div></div></div>
  • Re: appcmd IIS7/7.5 add Default Doc of type "remove"

    Mar 18, 2011 07:55 AM|itisdesign|LINK

    itisdesign


    <remove value="index.foo" />

    itisdesign


    <clear />

    Can appcmd add either of these to the default documents list?

    Even just a yes/no answer would help.  Tho, if the answer is yes, then it'd be helpful to know the syntax (since it's not documented).

    Thanks!,
    -Aaron Neff

  • Re: appcmd IIS7/7.5 add Default Doc of type "remove"

    Mar 20, 2011 04:25 AM|itisdesign|LINK

    Ok, here's a hack (only useful when creating a new site and web.config file.. don't use on existing sites).  Be sure to change index.foo's extension, in both the <add and <remove lines, to the preferred extension.  The code below is just a snippet of the relevant lines of an IIS7 site build batch script, to illustrate a workaround/hack for adding remove tags to the default document list.

    The 2 +files/-files lines are needed in order to write the <files></files> tag pair to web.config (these are then used by the hack).  The hack then reads each line from web.config, then replaces < and > with [ and ] (to allow searching), then searches for the string [files] within each line.  Every line not containing that string is copied to the web.config_temp temp file.  The line containing the [files] string is not copied to the temp file.  Rather, the proper lines (the remove/add lines) are written to the temp file, instead of that line.  The temp file then replaces the original web.config file.


    @echo off
    setlocal enabledelayedexpansion

    set IISAppCMD=%systemroot%\system32\inetsrv\appcmd.exe
    set siteName=mysitecom
    set sitePhysicalPath=C:\websites\mysitecom\www

    <snip>
    Code in here creates new site, new app pool, assigns app pool to root application, etc (thus building a new web.config file)
    </snip>

    REM Begin temporary workaround for appcmd.exe's inability to add "remove" elements
    REM ---------------------------------------------------------------------------------------------
    %IISAppCMD% set config "%siteName%" /section:defaultDocument /+files.[value='index.abcdef123456']
    %IISAppCMD% set config "%siteName%" /section:defaultDocument /-files.[value='index.abcdef123456']
    for /f "tokens=* delims=" %%i in (%sitePhysicalPath%\web.config) do (
      set xmlLine=%%i
      set xmlLine=!xmlLine:^<=[!
      set xmlLine=!xmlLine:^>=]!
      echo !xmlLine! | find /i "[files]"
      if errorlevel 1 (
        echo %%i>>%sitePhysicalPath%\web.config_temp
      ) else (
        echo             ^<files^>>>%sitePhysicalPath%\web.config_temp
        echo                 ^<remove value="index.foo" /^>>>%sitePhysicalPath%\web.config_temp
        echo                 ^<add value="index.foo" /^>>>%sitePhysicalPath%\web.config_temp
      )
    )
    move /y %sitePhysicalPath%\web.config_temp %sitePhysicalPath%\web.config
    REM ---------------------------------------------------------------------------------------------
    REM End temporary workaround for appcmd.exe's inability to add "remove" elements

    <snip>
    Code here continues building the web.config file
    </snip>

    No one has replied on this thread.  If this is a bug, can someone please log this against IIS 7.5?

    Thanks,
    -Aaron Neff

  • Re: appcmd IIS7/7.5 add Default Doc of type "remove"

    Mar 20, 2011 10:28 PM|Leo Tang - MSFT|LINK

    Hi, 

    itisdesign

    itisdesign


    <remove value="index.foo" />

    itisdesign


    <clear />

    Can appcmd add either of these to the default documents list?

    <Remove> is supported by appcmd, the command looks like:

    appcmd.exe set config "site's name" -section:system.webServer/defaultDocument /-"files.[value='index.foo']"

    appcmd does not support clearing a collection.

    You can generate the appcmd command by using Configuration Editor

    Using Configuration Editor: Generate Scripts

    http://learn.iis.net/page.aspx/417/using-configuration-editor-generate-scripts/

    Thanks.

    Please mark the replies as answers if they help or unmark if not.
    Feedback to us


  • Re: appcmd IIS7/7.5 add Default Doc of type "remove"

    Mar 20, 2011 11:25 PM|itisdesign|LINK

    Leo Tang - MSFT


    <Remove> is supported by appcmd, the command looks like:
    appcmd.exe set config "site's name" -section:system.webServer/defaultDocument /-"files.[value='index.foo']"

    Hi Leo,

    Exactly, yes, your command removes an <add />. This thread is not regarding removing an <add />.  This thread is regarding adding a <remove />:

    Example 1: Removing an <add value="index.foo" />

    Example 2: Adding a <remove value="index.foo" />

    IIS 7/web.config supports both example #1 & #2.  Your command addresses example #1.  My thread here is concerning example #2.  From what I've seen, appcmd.exe cannot insert <remove /> elements into web.config.

    Example (from web.config):
    <remove value="index.foo" />
    <add value="index.foo" />

    Is appcmd.exe able to generate those 2 lines into web.config?

    The page you linked to contains this broken link: Administration Pack V1 for IIS 7.0  That is a prerequisite in the referenced article, but that link to the prerequisite is broken.

    Thanks,
    -Aaron

  • Re: appcmd IIS7/7.5 add Default Doc of type "remove"

    Mar 22, 2011 11:43 PM|Leo Tang - MSFT|LINK

    Hi,

    I conformed that appcmd doesn't support add <clear/> tag in <files> collection by using "~", this is because <files/> is not defined as a configuration section in IIS schema. However, you can achieve this by using appcmd with xml file:

    xml file named CLEAR.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <appcmd>
        <CONFIG CONFIG.SECTION="system.webServer/defaultDocument" path="MACHINE/WEBROOT/APPHOST" overrideMode="Allow" locked="false">
            <system.webServer-defaultDocument enabled="true">
                <files>
                    <clear />
                </files>
            </system.webServer-defaultDocument>
        </CONFIG>
    </appcmd>

    Then run following command:

    appcmd set config /in "Site's name" < CLEAR.xml

    It also can be done by uing PowerShell cmdlet clear-webconfiguration or remove-webconfigurationproperty.

    itisdesign

    The page you linked to contains this broken link: Administration Pack V1 for IIS 7.0  That is a prerequisite in the referenced article, but that link to the prerequisite is broken.

    You can download it from here:

    http://www.iis.net/download/AdministrationPack

    With IIS7.5, Configuration Editor is built-in, you don't need to install AdministrationPack extension.

    Please mark the replies as answers if they help or unmark if not.
    Feedback to us