Skip to content

How do I add a section for URL Rewrite in web.config using WebConfigProperty? #647

@DennisL68

Description

@DennisL68

First, I'd like to apologies for being a jerk about commenting on all open issues about xThisRersource being legacy and not supported anymore.

Now to my question...

When automating a setup of an IIS site, I run into an issue that required me to use URL Rewrite.
However, I don't seem to get the grip of how to use the DSC Resource command WebConfigProperty correctly.

I've tried using

Configuration ConfigureRewriteRules {

  Import-DscResource -ModuleName WebAdministrationDsc -ModuleVersion 4.1.0
  Import-DscResource -ModuleName PSDesiredStateConfiguration

  node localhost {
    File 'Create_RewriteRulesFile' {
      Ensure          = 'Present'
      Type            = 'File'
      DestinationPath = 'c:\inetpub\wwwroot\rewriterules.config'
      Contents        = '<!-- some rules -->'
      Force           = $true
      MatchSource     = $true
    }

    WebConfigProperty 'Create_RewriteSection' {
      Ensure       = 'Present'
      WebSitePath  = 'MACHINE/WEBROOT/APPHOST/Default Web Site'
  #or WebSitePath  = 'IIS:\Sites\Default Web Site\'
      Filter       = 'system.WebServer/rewrite/rules'
      PropertyName = 'configSource'
      Value        = 'rewriterules.config'
      DependsOn    = '[File]Create_RewriteRulesFile'
    }

  }
}

ConfigureRewriteRules
Start-DscConfiguration -Path .\ConfigureRewriteRules -Wait -Verbose -Force

[WebConfigProperty]Create_RewriteSection will generate the error

Path doesn't belong to 'WebAdministration' provider.

and after adding the section system.WebServer/rewrite/rules by hand, the error will be

Property configSource is not found on /system.webServer/rewrite/rules

So most probably, I've got the parameter PropertyName wrong and something is wacky about the Filter I'm trying to use.

Note: I've specified Default Website for ease of use in this example, but I've verified that the specified path I've used do contain the web.config file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions