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>
This is explained in detail at https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api
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:
Post a Comment