Is there a default verb applied to a Web API ApiController method?

前端 未结 2 1364
一生所求
一生所求 2020-11-30 10:12

I\'ve been looking at the code (in https://github.com/patelsan/WebAPIAuthentication) from this article: http://www.codeproject.com/Articles/630986/Cross-Platform-Authenticat

2条回答
  •  有刺的猬
    2020-11-30 11:01

    File this under learning something new every day!

    Typically method name matching is thought of this way. Looking at the WebAPI source, however, there is a branch of logic for fallback. If the method name doesn't map (through attribute, or convention) to a supported HTTP verb, then the default is POST.

    By default action selection happens through ReflectedHttpActionDescriptor class. The important method here is GetSupportedHttpMethods(). In relevant part the code reads:

            if (supportedHttpMethods.Count == 0)
            {
                // Use POST as the default HttpMethod
                supportedHttpMethods.Add(HttpMethod.Post);
            }
    

    You can see the full source here (around the middle of the file).

提交回复
热议问题