8

What is the different between System.Web.Http.HttpPut and System.Web.Mvc.HttpPut?

Using [HttpPut] on the Web API project results the error 405 - The requested resource does not support http method 'PUT'.

2
  • Did you inherit your controller from Controller or from ApiController? Commented May 25, 2017 at 10:24
  • from ApiController Commented May 25, 2017 at 10:37

2 Answers 2

7

They belong to two different frameworks. The pipeline flow of each is looking for specific attributes that belong to their respective namespaces.

The routing engine for the respective frameworks are not aware of the other so if a Web API attribute is used on a MVC action it would be just as if there were no attribute at all, hence the 405 error encountered.

Make sure that the correct namespace is used on the correct controller type. If both namespaces are being used in the file then be specific by calling [System.Web.Http.HttpPut] for Web API actions

[System.Web.Http.HttpPut]
public IHttpActionResult Put([FromBody]MyModel model) { return Ok(); }

and [System.Web.Mvc.HttpPut] for MVC actions

[System.Web.Mvc.HttpPut]
public ActionResult Put([FromBody]MyModel model) { return View(); }
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply. However I didn't face any error when I use [HttpGet] either System.Web.Http.HttpGet or System.Web.Mvc.HttpGet, Only in [HttpPut].
Check your web config to see it PUT Verb is allowed for requests.
0

If you are in a MVC system application you should use System.Mvc.HttpPut It is the correct way because mvc pattern has many things that required mvc controls / methods.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.