Web APi之控制器选择Action方法过程(九)

前言

前面我们叙述了关于控制器创建的详细过程,在前面完成了对控制器的激活之后,就是根据控制器信息来查找匹配的Action方法,这就是本节要讲的内容。当请求过来时首先经过宿主处理管道然后进入Web API消息处理管道,接着就是控制器的创建和执行控制器即选择匹配的Action方法最终并作出响应(在Action方法上还涉及到模型绑定、过滤器等,后续讲)。从上知,这一系列大部分内容都已囊括,我们这一系列也就算快完事,在后面将根据这些管道事件以及相关的处理给出相应的练习来熟练掌握,希望此系列能帮助到想学习原理之人。

HttpControllerContext

我们回顾下此控制器上下文创建的过程:

HttpControllerContext = controllerContext = new HttpControllerContext(descriptor.Configuration,routeData,request)
{
   Controller = controller;
   ControllerDescrptor = descriptor
}

从上知以及从其名称可得知,控制器上下文就是将创建的控制器以及其描述信息封装到其中,方便调用而已。接下来就进入控制器上Action方法的选择,请往下看!

ApiController

相信大家对此类并不敏感,只要你创建了Web API控制器都是继承于该类,下面我们来看看此类的定义:

 1 public abstract class ApiController : IHttpController, IDisposable
 2 {
 3     // Fields
 4     private HttpConfiguration _configuration;
 5     private HttpControllerContext _controllerContext;
 6     private bool _disposed;
 7     private ModelStateDictionary _modelState;
 8     private HttpRequestMessage _request;
 9     private UrlHelper _urlHelper;
10
11     // Methods
12     protected ApiController();
13     public void Dispose();
14     protected virtual void Dispose(bool disposing);
15     public virtual Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken);
16 }

此上知该类为抽象类型,并在其中定义了一个ExecuteAsync()方法,此方法是此类中最重要的一个方法,因为控制器的执行过程就是在此方法中进行,下面我们继续来看看此方法的定义及实现。

 1 public virtual Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
 2 {
 3     if (this._request != null)
 4     {
 5         throw Error.InvalidOperation(SRResources.CannotSupportSingletonInstance, new object[] { typeof(ApiController).Name, typeof(IHttpControllerActivator).Name });
 6     }
 7     this.Initialize(controllerContext);
 8     if (this._request != null)
 9     {
10         this._request.RegisterForDispose(this);
11     }
12     HttpControllerDescriptor controllerDescriptor = controllerContext.ControllerDescriptor;
13     ServicesContainer controllerServices = controllerDescriptor.Configuration.Services;
14     HttpActionDescriptor actionDescriptor = controllerServices.GetActionSelector().SelectAction(controllerContext);
15     HttpActionContext actionContext = new HttpActionContext(controllerContext, actionDescriptor);
16 }

上述我只列出此节要讲的内容,有关过滤器以及其管道和授权等等都已略去,后续会讲。最重要的就是上述红色标记的四个了,下面我一一来查看:

第一步:HttpControllerDescriptor controllerDescriptor = controllerContenxt.ControllerDescriptor

在创建并激活控制器后其控制器上下文也同时生成,我们从控制器上下文中获得有关控制器的描述即HttpControllerDescriptor 

第二步:ServicesContainer controllerServices = controllerDescriptor.Configuration.Services;

从控制器的描述中的属性Configuration即HttpConfiguraion来获得其有关控制器的服务容器即Services

由于第三步涉及到其他类,此时我们将另起一段来叙述,请继续往下看!

HttpActionDescriptor

第三步:HttpActionDescriptor actionDescriptor = controllerServices.GetActionSelector().........

这一步就是重点所在,我们在前面叙述了多次关于服务容器ServicesContainer,这里不过是获得有关具体的服务容器而已,我们看看GetActionSelector方法:

public static IHttpActionSelector GetActionSelector(this ServicesContainer services)
{
    return services.GetServiceOrThrow<IHttpActionSelector>();
}

到了这里看过前面的文章相信大家不会陌生,就是从服务器容器中去获得我们注入的具体的实现。我们继续看看其子类DefaultServices具体实现到底是什么  

this.SetSingle<IHttpActionSelector>(new ApiControllerActionSelector());

ApiControllerActionSelector

从上得知,注入的服务为ApiControllerActionSelector类,我们继续追查此类:

 1 public class ApiControllerActionSelector : IHttpActionSelector
 2 {
 3     // Fields
 4     private readonly object _cacheKey;
 5     private ActionSelectorCacheItem _fastCache;
 6     private const string ActionRouteKey = "action";
 7     private const string ControllerRouteKey = "controller";
 8
 9     // Methods
10     public ApiControllerActionSelector();
11     public virtual ILookup<string, HttpActionDescriptor> GetActionMapping(HttpControllerDescriptor controllerDescriptor);
12     private ActionSelectorCacheItem GetInternalSelector(HttpControllerDescriptor controllerDescriptor);
13     public virtual HttpActionDescriptor SelectAction(HttpControllerContext controllerContext);
14
15     // Nested Types
16     private class ActionSelectorCacheItem
17     {
18         // Fields
19         private readonly ReflectedHttpActionDescriptor[] _actionDescriptors;
20         private readonly ILookup<string, ReflectedHttpActionDescriptor> _actionNameMapping;
21         private readonly IDictionary<ReflectedHttpActionDescriptor, string[]> _actionParameterNames;
22         private readonly HttpMethod[] _cacheListVerbKinds;
23         private readonly ReflectedHttpActionDescriptor[][] _cacheListVerbs;
24         private readonly HttpControllerDescriptor _controllerDescriptor;
25
26         // Methods
27         public ActionSelectorCacheItem(HttpControllerDescriptor controllerDescriptor);
28         private static string CreateAmbiguousMatchList(IEnumerable<HttpActionDescriptor> ambiguousDescriptors);
29         private ReflectedHttpActionDescriptor[] FindActionsForVerb(HttpMethod verb);
30         private ReflectedHttpActionDescriptor[] FindActionsForVerbWorker(HttpMethod verb);
31         private IEnumerable<ReflectedHttpActionDescriptor> FindActionUsingRouteAndQueryParameters(HttpControllerContext controllerContext, IEnumerable<ReflectedHttpActionDescriptor> actionsFound, bool hasActionRouteKey);
32         public ILookup<string, HttpActionDescriptor> GetActionMapping();
33         private static bool IsSubset(string[] actionParameters, HashSet<string> routeAndQueryParameters);
34         private static bool IsValidActionMethod(MethodInfo methodInfo);
35         private static List<ReflectedHttpActionDescriptor> RunSelectionFilters(HttpControllerContext controllerContext, IEnumerable<HttpActionDescriptor> descriptorsFound);
36         public HttpActionDescriptor SelectAction(HttpControllerContext controllerContext);
37
38         // Properties
39         public HttpControllerDescriptor HttpControllerDescriptor { get; }
40     }
41
42     private class LookupAdapter : ILookup<string, HttpActionDescriptor>, IEnumerable<IGrouping<string, HttpActionDescriptor>>, IEnumerable
43     {
44         // Fields
45         public ILookup<string, ReflectedHttpActionDescriptor> Source;
46
47         // Methods
48         public LookupAdapter();
49         public bool Contains(string key);
50         public IEnumerator<IGrouping<string, HttpActionDescriptor>> GetEnumerator();
51         IEnumerator IEnumerable.GetEnumerator();
52
53         // Properties
54         public int Count { get; }
55         public IEnumerable<HttpActionDescriptor> this[string key] { get; }
56     }
57 }

在此类中还额外包括两个私有的类: ActionSelectorCacheItem 和 LookupAdaper 。先保留这两个类,我们首先看看SelectAtion()方法

public virtual HttpActionDescriptor SelectAction(HttpControllerContext controllerContext)
{
    if (controllerContext == null)
    {
        throw Error.ArgumentNull("controllerContext");
    }
    return this.GetInternalSelector(controllerContext.ControllerDescriptor).SelectAction(controllerContext);
}

我们从此方法得知,此方法的实现本质是调用了返回值为  ActionSelectorCacheItem中的方法GetInternalSelector,我们从ActionSelectorCacheItem来猜此方法应该是生成一个控制器方法的缓存对象,所以此ActionSelectorCacheItem类型将是我们接下来介绍的重中之重。它被用来筛选Action()方法我们看看这个类:

 1 private class ActionSelectorCacheItem
 2 {
 3     // Fields
 4     private readonly ReflectedHttpActionDescriptor[] _actionDescriptors;
 5     private readonly ILookup<string, ReflectedHttpActionDescriptor> _actionNameMapping;
 6     private readonly IDictionary<ReflectedHttpActionDescriptor, string[]> _actionParameterNames;
 7     private readonly HttpMethod[] _cacheListVerbKinds;
 8     private readonly ReflectedHttpActionDescriptor[][] _cacheListVerbs;
 9     private readonly HttpControllerDescriptor _controllerDescriptor;
10
11     // Methods
12     public ActionSelectorCacheItem(HttpControllerDescriptor controllerDescriptor);
13     public HttpActionDescriptor SelectAction(HttpControllerContext controllerContext);
14
15     // Properties
16     public HttpControllerDescriptor HttpControllerDescriptor { get; }
17 }

以上四个属性并返回为相应的返回值是筛选方法的五个步骤之一,还有一个当然是构造函数的初始化了,这一切都将在构造函数中进行筛选,查看其构造函数:

public ActionSelectorCacheItem(HttpControllerDescriptor controllerDescriptor)
{
    this._actionParameterNames = new Dictionary<ReflectedHttpActionDescriptor, string[]>();
    this._cacheListVerbKinds = new HttpMethod[] { HttpMethod.Get, HttpMethod.Put, HttpMethod.Post };
    this._controllerDescriptor = controllerDescriptor;
    MethodInfo[] infoArray2 = Array.FindAll<MethodInfo>(this._controllerDescriptor.ControllerType.GetMethods(BindingFlags.Public | BindingFlags.Instance), new Predicate<MethodInfo>(ApiControllerActionSelector.ActionSelectorCacheItem.IsValidActionMethod));
    this._actionDescriptors = new ReflectedHttpActionDescriptor[infoArray2.Length];
    for (int i = 0; i < infoArray2.Length; i++)
    {
        MethodInfo methodInfo = infoArray2[i];
        ReflectedHttpActionDescriptor key = new ReflectedHttpActionDescriptor(this._controllerDescriptor, methodInfo);
        this._actionDescriptors[i] = key;
        HttpActionBinding actionBinding = key.ActionBinding;
        this._actionParameterNames.Add(key, (from binding in actionBinding.ParameterBindings
            where (!binding.Descriptor.IsOptional && TypeHelper.IsSimpleUnderlyingType(binding.Descriptor.ParameterType)) && binding.WillReadUri()
            select binding.Descriptor.Prefix ?? binding.Descriptor.ParameterName).ToArray<string>());
    }
    this._actionNameMapping = this._actionDescriptors.ToLookup<ReflectedHttpActionDescriptor, string>(actionDesc => actionDesc.ActionName, StringComparer.OrdinalIgnoreCase);
    int length = this._cacheListVerbKinds.Length;
    this._cacheListVerbs = new ReflectedHttpActionDescriptor[length][];
    for (int j = 0; j < length; j++)
    {
        this._cacheListVerbs[j] = this.FindActionsForVerbWorker(this._cacheListVerbKinds[j]);
    }
}

上述用五种颜色来标记五种筛选,我们由上至下一一进行简短解释:

  • 初始化筛选

通过传递进来的HttpControllerDesccriptor对象而给其该类此对象的变量属性,然后根据反射条件 BindingFlags.Public | BindingFlags.Instance 来获得控制器中的所有方法,最终保存在MethodInfo[]数组中。

  • ReflectedHttpActionDescriptor[] _actiondescriptors初始化

ReflectedHttpActionDescriptor是一个抽象类,通过上述已经控制器中的方法封装到MethodInfo[]数组中,此时将循环此数组并将每一个MehodInfo实例封装成ReflectedHttpActionDescriptor对象,并将每个实例封装到此对象数组中,通过该类名称,顾名思义也知,通过反射来获取Action方法的元数据信息。

  •  IDictionary<ReflectedHttpActionDesciptor,string[]> _actionparameterNames初始化

利用获得的ReflectedHttpActionDescriptor进行分析,并将其放到字典中,将此类作为键,而该方法的参数名称。

  • ILookup<string,ReflectedHttpActionDescriptor> _actionNameMapping初始化 

还是利用获得ReflectedHttpActionDescriptor来依据Action()方法名称来进行分组。

  • ReflectedHttpActionDescriptor[][] _cacheListVerbs初始化

利用获得的ReflectedHttpActionDescriptor进行依据Http方法类型来进行分类。

上面的五个只是初始化赋值,是为了下面筛选Action名称做准备,似乎有点难以理解,请看下面我们一一进行讲解!

Action名称筛选 

既然是筛选名称则要用到 ActionSelectorCacheItem 中的 SelectAction() 方法了,我们来仔细看看此方法的定义及实现:

public HttpActionDescriptor SelectAction(HttpControllerContext controllerContext)
{
    string str;
    ReflectedHttpActionDescriptor[] descriptorArray;
    Func<ReflectedHttpActionDescriptor, bool> predicate = null;
    bool hasActionRouteKey = controllerContext.RouteData.Values.TryGetValue<string>("action", out str);
    HttpMethod incomingMethod = controllerContext.Request.Method;
    if (hasActionRouteKey)
    {
        ReflectedHttpActionDescriptor[] source = this._actionNameMapping[str].ToArray<ReflectedHttpActionDescriptor>();
        if (source.Length == 0)
        {
            throw new HttpResponseException(controllerContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, Error.Format(SRResources.ResourceNotFound, new object[] { controllerContext.Request.RequestUri }), Error.Format(SRResources.ApiControllerActionSelector_ActionNameNotFound, new object[] { this._controllerDescriptor.ControllerName, str })));
        }
        if (predicate == null)
        {
            predicate = actionDescriptor => actionDescriptor.SupportedHttpMethods.Contains(incomingMethod);
        }
        descriptorArray = source.Where<ReflectedHttpActionDescriptor>(predicate).ToArray<ReflectedHttpActionDescriptor>();
    }
    else
    {
        descriptorArray = this.FindActionsForVerb(incomingMethod);
    }
    if (descriptorArray.Length == 0)
    {
        throw new HttpResponseException(controllerContext.Request.CreateErrorResponse(HttpStatusCode.MethodNotAllowed, Error.Format(SRResources.ApiControllerActionSelector_HttpMethodNotSupported, new object[] { incomingMethod })));
    }
    IEnumerable<ReflectedHttpActionDescriptor> descriptorsFound = this.FindActionUsingRouteAndQueryParameters(controllerContext, descriptorArray, hasActionRouteKey);
    List<ReflectedHttpActionDescriptor> list = RunSelectionFilters(controllerContext, descriptorsFound);
    descriptorArray = null;
    descriptorsFound = null;
    switch (list.Count)
    {
        case 0:
            throw new HttpResponseException(controllerContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, Error.Format(SRResources.ResourceNotFound, new object[] { controllerContext.Request.RequestUri }), Error.Format(SRResources.ApiControllerActionSelector_ActionNotFound, new object[] { this._controllerDescriptor.ControllerName })));

        case 1:
            return list[0];
    }
    string str2 = CreateAmbiguousMatchList((IEnumerable<HttpActionDescriptor>) list);
    throw Error.InvalidOperation(SRResources.ApiControllerActionSelector_AmbiguousMatch, new object[] { str2 });
}

我们通过前面的行号来讲解,我们知道在Web API的配置文件中默认是没有Action方法,当然你也手动配置Action方法,所以此时就会出现两种情况,由上亦知:

(6)我们从控制器上下文中获取路由对象RouteData,并且在其Values属性中查找action对应的值并返回该值

  • 若注册路由中有Action名称  

当查找到有Action名称时,看(10)根据上述初始化的_actionNameMapping来获得相应的action方法的元数据信息并返回一个ReflectedHttpActionDescriptor数组也就是source。再看(17)我们从ReflectedHttpActionDescriptor的属性集合SupportedHttpMethods即Http支持的方法中去找到根据从(7)控制器上下文中获得请求过来的Http方法,最后以(17)为条件获取到满足条件的元数据信息ReflectedHttpActionDescriptor数组即descriptorArray中。

关于此注册路由有Action名称的例子就不再叙述,与在MVC框架中请求Action方法类似。

  • 若注册路由无Action名称,则依据Http方法来决定Action方法名称

此时则利用上述初始化依据Http方法类型分类的_cacheListVerbs根据控制器上下文请求过来的方法类型来进行筛选决定其Http方法 ,我们举例来说明:

我们配置其路由为:  

  config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

我们的Action方法为:

        public void GetProduct(int id) { }

        public void PostProduct(int id) { }

        public void PutProduct(int id) { }

        public void DeleteProduct(int id) { }

        public void HeadProduct(int id) { }

当我们进行如下Get请求时:

            $.ajax({
                type: "get",
                url: "http://localhost:7114/api/product/1",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                cache: false,
                success: function (r) {
                    console.log(r);
                }
            });

此时会匹配到对应的如下Action方法:

其他的方法请求也类似Get除了Post之外,下面我们进行Post请求:  

观察此结果似乎也没什么不一样,No,我们在Action方法里再添加一个方法如下:

  public void Other(int id) { }

接下来我们再来进行Post请求,你会接收到如下响应错误

{"Message":"An error has occurred.","ExceptionMessage":"Multiple actions were found that match the request: \r\nVoid PostProduct(Int32) on type MvcWebApi.Controllers.ProductController\r\nVoid Other(Int32) on type MvcWebApi.Controllers.ProductController".......}

出错原因是有多个Action方法被匹配到,那么为什么会出现这样的错误呢?这就要说到约定了:

定义在控制器上的Action方法默认是仅支持一种Http方法,并且这个支持的Http方法决定于Action方法的名称,明确来讲,具有以上Action方法的前缀与对应的Http方法将默认支持,比如以上的GetProduct,那么默认只支持Get。但是如果Action名称没有这样的前缀,如以上的Other方法,那么默认支持Post。

基于以上默认约定,所以此时PostProduct和Other都会被匹配到,但是Action默认又仅支持一种Http方法,所以此时会出现如上错误。

这种有Action方法决定它所支持的Http方法的策略与RESET架构风格完全吻合,因为后者推荐直接采用Http方法来表示针对目标资源的操作方式,题外话,但是很多情况下,我们需要一个Action方法既支持Get又支持Post方法这个时候就需要用到ActionHttpMethodProvider特性解决。  

依据请求参数名称及个数筛选 

  • 有参数

在这种情况下,会先把路由数据对象的Values属性中的Keys值存放在一个集合A中,然后再获取当前请求的查询字符串集合,并且把集合中的所有Key值添加到集合A中,这就使的所有请求的参数名称都在一个集合中,然后就会从上述初始化的第二个的结果中根据当前的ReflectedHttpActionDescriptor类型实例(这里是接着上述初始化第三个的流程,所以这里是ReflectedHttpActionDescriptor类型的数组遍历执行)从_actionParameterNames获取对应的参数名称数组,然后是集合A会和获取的参数名称数组做一一的比较,看看集合A中是否包含参数名称,如果都有了则是满足条件。

这里返回的依然可能是ReflectedHttpActionDescriptor类型的数组,因为在一个方法有重载时,比如说Get(stringa)和Get(string a,string b)两个方法时,请求中如果有a和b两个参数的话,Get(string a)也是满足条件的。

  • 无参数

分别是利用 IActionMethodSelector、IActionMethodSelector以及IActionMethodSelector 来实现,就不再叙述,有兴趣的朋友可以查看其源码。

总结

关于控制器的执行选择Action方法用其详细示意图来表示,如下:来源【控制器执行过程】

未完待续:接下来将叙述过滤器,敬请期待。。。。。。。

时间: 2024-07-30 12:29:52

Web APi之控制器选择Action方法过程(九)的相关文章

Web APi之控制器创建过程及原理解析(八)

前言 中秋歇了歇,途中也时不时去看看有关创建控制器的原理以及解析,时间拖得比较长,实在是有点心有余而力不足,但又想着既然诺下了要写完原理一系列,还需有始有终.废话少说,直入主题. HttpControllerDispatcher 遗留问题 :在第六篇末尾所给图中有一个HttpControllerDispatcher未进行叙述,在本篇中去叙述正合时宜. 在第六篇我们也说过在Web API消息处理管道中的最后一个处理程序是HttpRoutingDispacher,它被用来激活控制器,这样说虽然没错,

.net mvc &amp;amp;amp; web api 之间的选择

问题描述 系统client:webbrowser,winform,手机app至于server端的选择:1,.netMVC=>browser:api=>winform和手机app2,webapi:client都通过webapi比较优缺点?和意见建议.谢谢指点啊!!分数实在是不多了. 解决方案 解决方案二:不用纠结了,在asp5中,这些都统一了.解决方案三:webapi吧,mvc天生不是用来做rest接口的解决方案四:有区别么,觉的没有...最终都能输出json..

asp.net web api如何获取调用Action之前的异常?

问题描述 比如404.content-type异常.参数转换异常等等. 解决方案 本帖最后由 ZZtiWater 于 2014-08-04 20:56:43 编辑解决方案二:actionfilter解决方案三:引用1楼liqiucu的回复: actionfilter 哥,能不能再详细一点,ActionFilter和ExceptionFilter我都没试出来!

Web APi之捕获请求原始内容的实现方法以及接受POST请求多个参数多种解决方案(十四)

前言 我们知道在Web APi中捕获原始请求的内容是肯定是很容易的,但是这句话并不是完全正确,前面我们是不是讨论过,在Web APi中,如果对于字符串发出非Get请求我们则会出错,为何?因为Web APi对于简单的值不能很好的映射.之前我们谈论过请求内容注意事项问题,本节我们将更加深入的来讨论这个问题,我们会循序渐进进行探讨,并给出可行的解决方案,.细细品,定让你收货多多! 捕获请求原始内容实现方法 捕获复杂属性值 Web APi对于复杂属性值以JSON或者XML的形式成功发送到服务器,基于这点

Web APi之过滤器创建过程原理解析【一】(十)

前言 Web API的简单流程就是从请求到执行到Action并最终作出响应,但是在这个过程有一把[筛子],那就是过滤器Filter,在从请求到Action这整个流程中使用Filter来进行相应的处理从而作出响应,这对于认证以及授权等是及其重要的,所以说过滤器应用是Web API框架中非常重要的一种实现方式,我们有必要去探讨其原理. 过滤器及其提供机制 Web API框架提供了一个请求.响应的消息处理管道,并且其框架极具扩展性,通过其扩展可以对执行的流程进行适当的干预,其扩展点就体现在以下三个方面

创建一个完整的ASP.NET Web API项目_实用技巧

Visual Studio为我们提供了专门用于创建ASP.NET Web API应用的项目模板,借助于此项目模板提供的向导,我们可以"一键式"创建一个完整的ASP.NET Web API项目.在项目创建过程中,Visual Studio会自动为我们添加必要的程序集引用和配置,甚至会为我们自动生成相关的代码,总之一句话:这种通过向导生成的项目在被创建之后其本身就是一个可执行的应用.一.通过VS2013..NET 4.5.1创建一个Web API项目1.解决方案下面新建项目 2.选择项目W

ASP.NET Web API实现POST报文的构造与推送

  毕设和OAuth协议相关,而要理解OAuth协议就必须理解HTTP GET/POST方法.因此研究了一下如何使用Web API或MVC构造POST报文并实现客户端与服务器端的交互. 我使用的工具是Visual Studio 2013 + Web API 2 + MVC 5. 在两个不同的VS2013实例中分别新建两个Web项目,都选择空模板,其中一个命名为Client,采用MVC架构,另一个命名为Server,采用Web API架构. 这里需要两个不同的VS2013实例是为了能使两个IIS

Web API路由

译者:jiankunking 出处:http://blog.csdn.net/jiankunking 原文地址 本文讲解ASP.NET Web API如何将HTTP请求路由至控制器. 如果你熟悉ASP.NET MVC,Web API路由与MVC路由非常相似.主要差别是Web API使用HTTP方法,而不是URI路径来选择Action.你也可以按照之前配置MVC路由的方式来配置Web API路由.本文不需要任何ASP.NET MVC知识. Routing Tables路由表 在Asp.Net We

Asp.Net Web API 2第五课——Web API路由

原文:Asp.Net Web API 2第五课--Web API路由 Asp.Net Web API 导航   Asp.Net Web API第一课--入门 http://www.cnblogs.com/aehyok/p/3432158.html       Asp.Net Web API第二课--CRUD操作 http://www.cnblogs.com/aehyok/p/3434578.html       Asp.Net Web API第三课--.NET客户端调用Web API http: