web api

Enable PUT and DELETE in IIS

Context

    • IIS with WebDav
    • WebDav is not required

Problem

Original Web.config:

<modules >

<remove name="FormsAuthentication" />

</modules>

<handlers>

<remove name="ExtensionlessUrlHandler-Integrated-4.0" />

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

</handlers>

</modules >

Related errors:

    • HTTP Error 405.0 - Method Not Allowed from WebDAVModule

Solution

Web.config:

<modules runAllManagedModulesForAllRequests="true">

<remove name="WebDAVModule" />

<remove name="FormsAuthentication" />

</modules>

<handlers>

<remove name="WebDAV" />

<remove name="ExtensionlessUrlHandler-Integrated-4.0" />

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

</handlers>

</modules >

IIS:

  1. select site
  2. webdav authorizing rules
  3. disable webdav

How to Rollback a Database Migration From a Remote SQL Server

The scope of this solution is to explain how to recover from a desynchronization between your project database version and your remote server database. How to correctly rollback in both development and remote servers is out of scope.

Scenario:

    1. You apply the last migration last_migration.cs both at the development and remote (test or production) server
    2. You rollback the last migration from your development server by issuing: update-database -targetMigration previous_to_the_last_migration.cs
  1. You remove the file last_migration.cs from your development server. Mistake!
    1. You want to apply the rollback to the remote server and you publish your project. You get an error!
    2. You cannot simply remove the entire database and regenerate it again because it contains plenty of data. You need a solution!

Solution 1:

If you had open ports to connect to remotely to the SQL Server, then you simply do: update-database -targetMigration previous_to_the_last_migration.cs -ConnectionString "YOURCONNECTIONSTRING".

Solution 2:

Given that you do have access to the remote server by e.g. a RDP connection, we'll make use of SQL Server Management Studio (SSMS):

    1. Log in SSMS,
  1. Open the database
  2. Edit table __MigrationHistory
    1. Delete the line with MigrationId "last_migration"
    2. Revert the changes applied by last_migration.cs manually at the corresponding database tables
    3. Publish the project again
    4. Done