3

I know that Core 2 is moving away from the web.config and towards Json configuration. However, I have come across an issue where by my IIS 7 server has WebDav installed which is blocking HTTP PUT requests to my webapi.

The following link has provided a working solution by removing WebDav;

Remove WebDav Web.Config for Core 1

The issue I am having is that I need to add this to the generated web.config on the server with every publish as it is being over written each time.

Is it possible for me to add a web.config to my Asp.Net Core 2 webapi? or tell it to add this to the one it is generating?

Matthew Flynn
  • 3,661
  • 7
  • 40
  • 98

2 Answers2

1

In Asp.Net Core 2.1 I added web.config file into the root of project then remove WebDAV from module and handler

<system.webServer>
        <modules runAllManagedModulesForAllRequests="false" xdt:Transform="Insert" >
            <remove name="WebDAVModule" />
        </modules>
        <handlers>
            <remove name="WebDAV"/>
         </handlers>
</system.webServer>

The web.config file is generated when you are publishing the project. It works for me.

0

You can just add 'copy always' property to any file to auto add it to the build folder.

enter image description here

also you can use config file transformations. I believe they should work with .Net Core. In your case you want to create web.release.config:

Right-click the Web.config file and then click Add Config Transforms.

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="false" xdt:Transform="Insert" >
      <remove name="WebDAVModule" />
    </modules>
  </system.webServer>
</configuration>

More information

Good example

Curly Brace
  • 515
  • 3
  • 13
  • 1
    But I’m using.net core – Matthew Flynn Apr 24 '18 at 04:21
  • You can add 'copy always' property to any file to auto add it on build. Edited my answer. – Curly Brace Apr 24 '18 at 04:34
  • 1
    Thanks for the deatiled answer, but the issue is I am using .net core 2. Visual Studio isn't giving me the option to add transformations to a web.config file, and errors when I try to debug if I add a web.config file to the project? – Matthew Flynn Apr 24 '18 at 09:01
  • Publishing my Core 2 project generates the `web.config` and wondering how to bring this file into the solution/project for purposes of configuration management. – Adam Cox Jun 25 '18 at 20:33
  • @MatthewFlynn Did you manage to find a solution to the .NET Core 2.0 web.config issue? I too need to remove the WebDav when I publish. Any help would be greatly appreciated. – Dickie Watkins Jul 31 '18 at 13:31
  • In the end I added a new web.config file to the solution https://www.pastiebin.com/5b606561c6c56 – Matthew Flynn Jul 31 '18 at 13:34