Web.API MapHttpRoute parameters

前端 未结 3 1307
小蘑菇
小蘑菇 2021-02-04 02:48

I\'m having problems with my Web.API routing. I have the following two routes:

config.Routes.MapHttpRoute(
    name: \"Me         


        
3条回答
  •  渐次进展
    2021-02-04 03:01

    From http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-and-action-selection

    You can also provide constraints, which restrict how a URI segment can match a placeholder:

    constraints: new { id = @"\d+" } // Only matches if "id" is one or more digits.

    Adding this constraint to "MethodOne" (api/{controller}/{action}/{id}/{type}) would mean that numbers it only matches if {id} is a number otherwise it would match "MethodTwo" ("api/{controller}/{action}/{directory}/{report}").

提交回复
热议问题