C# Question

Attribute Routing in Web API with RoutePrefix - Strange error

public class ServiceRequestController : ApiController
public IHttpActionResult Post([FromBody]ServiceRequest.Models.ServiceRequest serviceRequest)
return Ok();

I use an empty
for a
and invoke


This throws an error stating
HTTP Error 405.0 - Method Not Allowed
and most likely causes given were

  • The request sent to the Web server used an HTTP verb that is not
    allowed by the module configured to handle the request


    A request was sent to the server that contained an invalid HTTP verb


    The request is for static content and contains an HTTP verb other
    than GET or HEAD


    A request was sent to a virtual directory using the HTTP verb POST
    and the default document is a static file that does not support HTTP
    verbs other than GET or HEAD.

However if use Route("Test"), the method
just works fine
as like below:

[POST] to http://localhost.com:59985/ServiceRequest/Test -- works fine.
(Route is [Route("Test")])

[POST] to http://localhost.com:59985/ServiceRequest ------- does not work
(Route is [Route("")]

Is empty
not allowed for POST ?
Any ideas what is wrong here ?

Answer Source

Turns out to be some issue because the [RoutePrefix("ServiceRequest")] had the same name as the controller name.

When I changed the [RoutePrefix()] everything worked fine as before.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download