How to remove WebDav in Startup.cs ASP.NET Core

Viewed 4196

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

4 Answers

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

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.

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>

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>
Related