I am making delete requests from an AngularJS app to an asp.net web api and I am getting below error -
XMLHttpRequest cannot load http://api.prod.com/api/v1/proddetails/34. No
'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:5100' is therefore not allowed access. The response
had HTTP status code 403.
Method:
[HttpDelete]
public HttpResponseMessage Delete(int id)
Web Config:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
<remove name="WebDAVModule" />
</modules>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="12582912" />
<!--12 MB-->
</requestFiltering>
</security>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<remove name="WebDAV" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
Please help.
Note: The machine is a Windows Server 2012 R2 running IIS 8.5 on AWS EC2. I have CORS setup properly like this on the controller -
[EnableCors(origins: "*", headers: "*", methods: "*")]
Edit1:
I was looking at my applicationHost.config file, and it has these lines -
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
But there are so many of them, and none of them have DELETE as allowed verb. Can this be causing an issue?
Edit2:
As requested, this is the AngularJS request code -
$http.delete('http://api.prod.com/api/v1/proddetails/' + data)
.success(function (data, status, headers, config) {
console.log(data);
if(data.status == "200")
{
console.log('data deleted');
}
deferred.resolve(data);
})
.error(function (data, status, headers, config) {
console.log("some error occurred");
deferred.reject(data);
});