[在使用WebAPI之前 一直使用Controller return Content("[Json]");来输出内容  
所以使用上WEBAPI只是一直由路由包装,根据请求方式默认配置的特殊controller???] 
 
路由规则 (与普通Controller并不在一起)
 public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: ".api",
                routeTemplate: "{controller}/{action}.api",
                defaults: new { id = RouteParameter.Optional }
            );//自定义路由规则
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
 
            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
            //config.EnableQuerySupport();
        }
    }

  

默认webapi不需要提供相应action[Controller,Action不区分大小写~]
根据请求方式
如果是以GET的方式请求的那么将匹配controller中以“Get”开头的Action

如果是以POST的方式请求的那么将匹配controller中以“Post”开头的Action

如果是以PUT的方式请求的那么将匹配controller中以“Put”开头的Action

如果是以DELETE的方式请求的那么将匹配controller中以“Delete”开头的Action

 

根据请求返回类型不同,同一接口返回可以是json,xml或者text文本
[xml返回类型为dynamic会出错~]

 

 

同时可以方法特性来标记一个方法属于什么什么请求

 [HttpGet]
        public IEnumerable<Test_User> POST()
        {
            return iList;
        }
//等价于
         public IEnumerable<Test_User> GET()
        {
            return iList;
        }
//[!]同存会报错(但是可以根据自定义规则,通过具体action来访问)
//