11

I published a .NET Core Web API through FTP.

By default, some of the methods weren't working(put and delete), because the server has WebDAV enabled as default.

To remove this, after publishing the application I have to manually go to web.config on FTP and add the following lines

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

How would one go about it setting it up to be removed automatically - I assume through Startup.cs

Ade Stringer
  • 2,611
  • 17
  • 28
BroDev
  • 582
  • 1
  • 4
  • 14
  • https://stackoverflow.com/questions/48188895/asp-net-core-with-iis-http-verb-not-allowed this may help, and this seems to be a duplicate – Dreamweaver Mar 11 '20 at 16:17
  • 2
    As it seems, the answers to that question clarify the same solution which I have used. However, they don't answer the question which I've asked – BroDev Mar 11 '20 at 16:29
  • You can have web.config for production and DEV and while build / publish we can publish production webconfig. Will it not work ? – Dreamweaver Mar 12 '20 at 03:37
  • 2
    @Dreamweaver The standard VS2019 project doesn't contain web config as before. It gets created after publishing to the FTP and you need to manually override it, etc. The question is, how to simply remove WebDav through Startup.cs I think it should be possible – BroDev Mar 12 '20 at 13:30

5 Answers5

4

You only need to add web.config file to your API, and then when you publish automatically it will take your web.config.

jlmpulido
  • 41
  • 2
1

bro, I have tried, but this is what worked for me.

but I succeeded by going to the published files and opening the web.config file.

there I made some changes to look like below.

<system.webServer>
 <modules>
   <remove name="WebDAVModule" />
 </modules>

 <handlers>
  <remove name="WebDAV" />
  <add name="aspNetCore" path="*" verb="*" 
      modules="AspNetCoreModuleV2" resourceType="Unspecified" />
  </handlers>
  <aspNetCore processPath="dotnet" arguments=".\#.dll" stdoutLogEnabled="#" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
Rikudou En Sof
  • 526
  • 1
  • 4
  • 21
1

I was in a similar pickle. But I am able to configure commands to run after deployment on my server. If you are able to do the same, run

appcmd delete module WebDAVModule /site.name:"MyWebSite"

commmand in the C:\Windows\System32\inetsrv> path.

salman_sali
  • 181
  • 2
  • 8
  • Worked perfectly, though I don't think you need to be in the `C:\Windows\System32\inetsrv` path as I wasn't. – Tarkan Feb 15 '23 at 14:48
0

You have to remove WebDAVModule from iis server.

Steps:

  1. Go to your site in IIS
  2. Click "Modules"
  3. Remove WebDAVModule
  4. Restart site (might not be needed)

PUT and DELETE requests should now work.

  • 1
    Read the question again carefully. It's not about removing it, it's about setting it up to do it automatically. – BroDev Oct 08 '21 at 19:11
-1

Add this code to your web config file:

   <system.webServer>
        <modules>
          <!-- Remove WebDAV module so that we can make DELETE requests -->
          <remove name="WebDAVModule" />
        </modules>
        <handlers>
          <!-- Remove WebDAV module so that we can make DELETE requests -->
          <remove name="WebDAV" />
          <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
        </handlers>
    
        other configs here...
    
    
    </system.webServer>
funie200
  • 3,688
  • 5
  • 21
  • 34
  • 1
    The question is not about how to Remove WebDAV with .NET Core. The question is about how to automate the process. Thank you – BroDev Dec 08 '20 at 17:16
  • BroDev, you cannot automate it without removing the WebDavModule. One way to do this is to remove the WebDavModule in IIS. This is still manual. I also found out that if the server is restarted, the default settings will be reinstalled. Another way to do this is to add web.config to your web project and add the script from @Kamran Mammadov – makinyelure Jul 25 '22 at 12:23