10

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,531
  • 16
  • 27
BroDev
  • 538
  • 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
  • 1
    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

4 Answers4

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

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.

  • 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
0

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>
-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,294
  • 5
  • 19
  • 31
  • 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