MVC WebAPI Routing issue

I was trying to use attribute routing in a project but having issues. Calling an action by its real name was working fine, but if I would put a route attribute on the action and try to call it with the route, it would return a 405 error: (The requested resource does not support http method ‘GET’.)

From other posts I found, I felt like everyone was fixing this issue by putting an [HttpGet] attribute on their action, so I tried that:

        [Route("Next")]
        [HttpGet]
        public IEnumerable GetNextTasks()
        {

This didn’t work either. Finally I found a post where someone said they fixed it by chaining the attributes so I tried that and it worked. So here is an example of what finally worked:

        [Route("Next"),HttpGet]
        public IEnumerable GetNextTasks()
        {

*This is not needed for POST transactions because POSTS are the default.
** This is not needed for a GET if the get is the only the GET and the action is named GET.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s