HTTP删除 - 授权问题

时间:2017-11-30 00:35:51

标签: angular

我有一个调用web api的角度应用程序服务。 Web API具有Get服务,如果从我的角度应用程序调用它们可以正常工作,但是,如果调用HTTP删除,我会收到错误(405(方法不允许)。由于HTTPGET工作,它不会成为CORS的问题还通过Fiddler测试了删除服务,工作正常。当我从我的角应用程序中点击web api服务时出现错误。

这是我的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。没有Getusers服务问题,只有Delusers服务导致问题

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>

0 个答案:

没有答案