Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

The requested resource does not support the method http 'PUT'

$
0
0

I'm developing a Web Api 2 service with latest .NET Framework and C#.

I have a controller with these methods:

    public IEnumerable<User> Get()
    {
        // ...
    }
    public User Get(int id)
    {
        // ...
    }
    public HttpResponseMessage Post(HttpRequestMessage request, User user)
    {
        // ...
    }
    public void Put(int userId, User user)
    {
        // ...
    }

And this is `WebApiConfig` class

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Web API routes
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }

When I try to do a PUT on api/Users/4 I get an error telling me that it only allows GET. This is the response when I do a Put:

    HTTP/1.1 405 Method Not Allowed
    Cache-Control: no-cache
    Pragma: no-cache
    Allow: GET
    Content-Type: application/json; charset=utf-8
    Expires: -1
    Server: Microsoft-IIS/8.0
    X-AspNet-Version: 4.0.30319
    X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcVWljMTguSUNcU291cmNlc1xSZXBvc1xWaWEgQ29nbml0YVxNYXR0XHNyY1xNYXR0LlNvY2lhbE5ldHdvcmsuV2ViLkFwaVxhcGlcVXNlcnNcMQ==?=
    X-Powered-By: ASP.NET
    Date: Thu, 04 Sep 2014 10:04:26 GMT
    Content-Length: 68
    {"Message":"The requested resource does not support the method http 'PUT'."}

Do you know why I'm getting this error?


Viewing all articles
Browse latest Browse all 4850

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>