What is the default behaviour of a controller action not marked with AcceptVerbs, HttpGet or HttpPost?

后端 未结 2 1099
轻奢々
轻奢々 2021-01-11 14:17

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

D

相关标签:
2条回答
  • 2021-01-11 15:08

    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"; }
    }
    
    0 讨论(0)
  • 2021-01-11 15:15

    It's accessible via any verb.

    0 讨论(0)
提交回复
热议问题