I have this very simple PUT Action Method
- public class FeedItemController : ApiController
- {
- [HttpPut()]
- public void Put(int id, string status)
- {
- }
- }
And the corresponding jQuery script:
- var url = '@Url.RouteUrl("DefaultApi",new { httproute="", controller="FeedItem", id=2,status="done"})';
- $.ajax({
- url: url,
- type: 'PUT',
- success: function (result) {
- // ...
- }
- });
No matter what I tried I always got a 404 error…
Finally, I gave up changing code and looked at the debugging environment and I found that I was using IIS Express for debugging.
I changed it to “Use Visual Studio Development Server” and voila it worked!
Apparently IIS Express is not configured by default to support the PUT word. To change this open up “C:\Users\<YourUserName>\Documents\IISExpress\config\applicationhost.config” and change the line for the “ExtensionlessUrl-Integrated-4.0” handler to
- <add name="ExtensionlessUrl-Integrated-4.0" path="*." verb="GET,HEAD,POST,PUT,DELETE,DEBUG" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
And don’t forget to add the PUT word to your production IIS server ;)
Ingen kommentarer:
Legg inn en kommentar