简体   繁体   中英

How to remove WebDav from IIS, in .NET 5.0?

We have a Web API webservice site, built in .NET 4.5.2, that we're trying to move to .NET 5.0.

We ran into what seems to be a common issue - when we deploy the site to our staging environment, none of the PUT and DELETE methods work. When we test them using the generated Swagger UI, we get 500 errors.

Note - we do not see these errors running in IIS Express, through the VS2019 debugger.

We browse the web, of course, and find an answer:

How do you fix a 500 Server Error while running REST PUT or DELETE requests?

So we create a web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <remove name="WebDAV" />
    </handlers>
    <modules>
      <remove name="WebDAVModule" />
    </modules>
  </system.webServer>
</configuration>

And that causes different problems.

  1. We get HTTP 500 errors when we try to run the site in IIS Express through the VS2019 debugger, and
  2. Running the site modifies the web.config.

The web.config now looks like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <remove name="WebDAV" />
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <modules>
      <remove name="WebDAVModule" />
    </modules>
    <aspNetCore stdoutLogEnabled="false" hostingModel="InProcess" />
  </system.webServer>
</configuration>

Note the addition of aspNetCore.

So, here's the thing.

  • We need this to work both when deployed to IIS, and when run locally, and
  • We can't have source files that are partially generated, during the build. Our whole build-and-version-control system is built on the idea that there are files that contain code that developers write and there are files that are generated during the build. The former we save version control and the latter we do not. We can add web.config to our version control, but if we do we cannot have its contents changing during a build or run.

So, what do we do?

How do we get this to work when deployed in IIS and when run in IIS Express when debugging?

And how do we deal with the web.config being modified during a debug run?

These sort of issues seem to show up for a great many reasons, and I can't pretend to have found an answer to all of them.

In this particular case, the problem was that VS was inserting bad elements into the web.config.

Adding the <handlers/> and <modules/> elements to remove the WebDAV caused VS to insert an <aspNetCore/> element:

<aspNetCore stdoutLogEnabled="false" hostingModel="InProcess" />

And the element that was inserted lacked the required processPath= attribute.

<aspNetCore processPath="dotnet" stdoutLogEnabled="false" hostingModel="InProcess" />

It is better to turn off WebDAV Publishing. To do that: Open "Turn Windows Features on or off". Now inside Internet Information Services\World Wide Web Services\Common HTTP Features\WebDAV Publishing. Uncheck it and click OK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM