locked
Modify IIS app config settings RRS feed

  • Question

  • Hi everyone, 

    I am trying to modify an IIS site application settings. I would like the sections HTTP protocol and verbs setting to be removed from my web.config file, but I do not want to use the <g class="gr_ gr_379 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="379" id="379">xml</g> commands and I want to use <g class="gr_ gr_515 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="515" id="515">powershell</g>. Since this is at the application level and not the site level I am running into issues with it. Below is what the document looks like now:

    <system.webServer>
        <httpProtocol>
          <customHeaders>
            <!--Override the IE broweser's Compatibility View Settings for intranet sites.-->
            <add name="X-UA-Compatible" value="IE=Edge" />
            <add name="X-Frame-Options" value="SAMEORIGIN" />
          </customHeaders>
        </httpProtocol>
        <security>
          <requestFiltering>
            <!--This is needed to support uploading large byte arrays.-->
            <requestLimits maxAllowedContentLength="209715200" />
            <!--Disabling OPTIONS per security assessment recommendation-->
            <verbs allowUnlisted="true">
              <add verb="OPTIONS" allowed="false" />
            </verbs>
          </requestFiltering>
        </security>

    The end result I need in the config file is:

    <system.webServer>
        <security>
          <requestFiltering>
            <!--This is needed to support uploading large byte arrays.-->
            <requestLimits maxAllowedContentLength="209715200" />
            <!--Disabling OPTIONS per security assessment recommendation-->
          </requestFiltering>
        </security>

    All the config files are different for this per application so a replacement of the file is not going to work here. The commands I had been running (except I add in my site name and app name and dont leave it as site name and app name in the command) are:

    Remove-WebConfigurationProperty -PSPath 'IIS:\Sites\site name\app name' -Filter 'system.webServer/security/requestFiltering' -name verbs -atelement @{verb="OPTIONS";allowed='false'} 
    Remove-WebConfigurationProperty -PSPath 'IIS:\Sites\site name\app name' -Filter 'system.webServer/security/requestFiltering' -name verbs -atelement @{verb="OPTIONS";allowed='false'}
    Remove-WebConfigurationProperty -PSPath 'IIS:\Sites\site name\app name' -Filter 'system.webServer/httpProtocol' -name customHeaders -atelement @{name="X-Frame-Options";value='SAMEORIGIN'} 
    Remove-WebConfigurationProperty -PSPath 'IIS:\Sites\site name\app name' -Filter 'system.webServer/httpProtocol' -name customHeaders -atelement @{name="X-Frame-Options";value='SAMEORIGIN'} 

    Any help would be appreciated. Again, this is at the application level and not the site level and I want to user powershell without XML commands. 

    Let me know, thank you!


    Thursday, November 1, 2018 4:02 PM

All replies

  • You probably might be better of in the IIS.NET Forums : The Official Microsoft IIS Forums.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    • Proposed as answer by jrv Thursday, November 1, 2018 7:55 PM
    Thursday, November 1, 2018 4:10 PM
  • I hate to break it to you but both the applicationhost.config and web.config files are XML.  Avoiding working with them as XML in PowerShell is counterproductive.

    Also, you're missing a closing </system.webServer> tag in your config which makes it invalid XML.  Hopefully that's not why you were avoiding using XML functions.

    With Valid XML, removing an entire node from XML is trivial.

    $xml.SelectNodes("system.webServer").ChildNodes | Where-Object {$_.Name -match "httpProtocol"} | %{$_.ParentNode.RemoveChild($_)}

    https://gist.github.com/msm-fc/92bb3c2e91a858e8f7842b74a7af3e3d#file-remove_xml_nodes-ps1

    Friday, November 2, 2018 5:37 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    Best Regards,

    Lee


    Just do it.

    Friday, November 9, 2018 7:45 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Tuesday, December 4, 2018 2:29 AM