问题
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