Friday, November 22, 2019

Configure MVC app to receive and handle OPTIONS requests

Many of the frequently used http request methods are readily available from within MVC controllers. e.g, GET, PUT, POST, DELETE, etc.

However, there is also one important HTTP request method OPTIONS, which is sent before any CORS request to check if the request is allowed. This method is normally handled automatically by MVC framework, but if we ever need to handle it inside our controller, then add following tags to web.config


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

</system.webServer>



This is explained in detail at https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api



No comments:

SSL Error - The connection for this site is not secure

 After cloning a git repo of dot net framework website and trying to run it all I could see was this error Turns out the fix was to simply e...