I have an angular application service that calls a web api. The Web API have Get services which they work fine if called from my angular application, however, if HTTP delete is called , i get error (405 (Method Not Allowed). It can't be an issue with CORS since HTTPGET works. Also tested the Delete service via Fiddler , which works fine. the errors occurs when I hit the web api service from my angular application.
here is my service.ts
constructor(private _http: Http)
{
delusers(id: number) {
return this._http.delete(environment.BASE_API_URL + 'Delusers/' + id)
.map((response: Response) => response.json())
.do(data => console.log('All' + JSON.stringify(data)))
.catch(this.handleError);
}
web api , controller.No issues with Getusers service , only Delusers service cause the issue
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Http.Cors;
namespace ERSA.WebAPI.Controllers
{
[EnableCors(origins: "*", headers: "*", methods: "*")]
public class ERSAController : ApiController
{
ERSAFactory _modelFactory = new ERSAFactory();
[HttpGet]
[Route("API/GetUsers/{userID}")]
public HttpResponseMessage Getuers(string userID)
{
..some code
}
[HttpDelete]
[Route("API/Delusers/{id}")]
public HttpResponseMessage Delusers(int id)
{
...some code
}
}
}
web api config
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>