Pergunta

If I create a controller action and do not decorate it with AcceptVerbs, HttpPost or HttpGet. What is the default behaviour?

Does the action allow any access method or does it default to GET?

Foi útil?

Solução

It's accessible via any verb.

Outras dicas

In Web API 2.1:

it depends on the name of the action. If the action starts with "Get*" then it will default to only accept GET requests. If it starts with "Put*" then it will default to only accept PUT requests. Same with POST.

If it doesn't start with any known verb then it will default to only accept POST.

Here are the results of my testing:

public class BlahController : ApiController
{
    // only allows GET
    public string GetSomething() { return "GetSomething blah"; }

    // only allows PUT
    public string PutSomething() { return "PutSomething blah"; }

    // only allows POST
    public string PostSomething() { return "PostSomething blah"; }

    // only allows POST
    public string Fleabag() { return "Fleabag blah"; }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top