Web API 405 Method Not Allowed In Remote

筅森魡賤 提交于 2019-12-11 20:36:34

问题


Following is one my action:

public IHttpActionResult PutUnit(int id, Unit unit)
{
    if (!ModelState.IsValid)
        return BadRequest(ModelState);

    if (id != unit.UnitId)
        return BadRequest();

    db.Entry(unit).State = EntityState.Modified;

    try
    {
        db.SaveChanges();
    }
    catch (DbUpdateConcurrencyException)
    {
        if (!UnitExists(id))
        {
            return NotFound();
        }
        else
        {
            throw;
        }
    }

    return StatusCode(HttpStatusCode.NoContent);
}

Following is the response I get:

Date: Tue, 19 Aug 2014 10:30:31 GMT
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Allow: GET, HEAD, OPTIONS, TRACE
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Content-Type: text/html
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Content-Length: 1293

All actions of my controller works fine locally but once I deployed the same project on a remote server. I could not access only PUT and DELETE actions of my controller instead got the 405/Method Not Allowed error. web.config and webapiconfig.cs are same and using the default structure. Any suggestion please?


回答1:


Take a look at Enabling The PUT Verb with Handlers and IIS 7.0



来源:https://stackoverflow.com/questions/25382069/web-api-405-method-not-allowed-in-remote

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!