1

I need to add the following to my published web.config;

<modules runAllManagedModulesForAllRequests="false">
    <remove name="WebDAVModule" />
</modules>

that I am publishing with Asp.Net Core 2, however, it doesnt seem to be working;

$webConfig = (Get-Item -Path ".\").FullName + "\Bemfeito.Services.WebApi\obj\Release\netcoreapp2.0\PubTmp\Out\web.config"
$doc = (gc $webConfig) -as [Xml]

$moduleNode = $doc.CreateElement("modules")
$moduleNode.SetAttribute("runAllManagedModulesForAllRequests", "false")
$removeNode = $moduleNode.CreateElement("remove")
$removeNode.SetAttribute("name","WebDAVModule")
$moduleNode.AppendChild($removeNode)

$doc.configuration.system.webServer.AppendChild($moduleNode)

$doc.Save($webConfig)

(I am adding this as a prepublish option on my webdeploy) I think it has something to do with not grabbing and/or commiting the saves correctly? can someone please advise me on where I am going wrong?

3
  • I think the issue is with loading the web.config file as I have debugged the script using and have tried gc web.config, get-content web.config, gc "$pwd\web.config", Resolve-Path "web.config" and Resolve-Path web.config (the web.config is in the same directory as a test when i run the script) Also I am using Visual Studio powershell tools i.e. right click and execute script on the .ps1 file Commented May 3, 2018 at 11:24
  • however is I use a full path i.e. C:\\.....\web.config this works? any idea on using the current working directory? Commented May 3, 2018 at 11:28
  • Thanks for the reply. I've literally just managed to get the xml to now load. It now doesnt seem to be adding the xml? I've updated the code to match what I have currently. Now it doesn tseem to be adding to the node tree? Commented May 3, 2018 at 11:43

1 Answer 1

1

There was a number of issues with appending to the node but the main one turned out to be the fact I was appending to configuration.system.webServer.AppendChild. In fact this should have been configuartion.'system.webServer'.AppendChild

For reference my full script is;

$webConfig = (Get-Item -Path ".\").FullName + 

"\Services.WebApi\obj\Release\netcoreapp2.0\PubTmp\Out\web.config"
$doc = (gc $webConfig) -as [Xml]

$moduleNode = $doc.CreateElement("modules")
$moduleNode.SetAttribute("runAllManagedModulesForAllRequests", "false")


$removeNode = $doc.CreateElement("remove")
$removeNode.SetAttribute("name","WebDAVModule")
$moduleNode.AppendChild($removeNode)

$doc.configuration.'system.webServer'.AppendChild($moduleNode)

$doc.Save($webConfig)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.