1 / 13
文档名称:

路由与动作选择.docx

格式:docx   大小:24KB   页数:13页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

路由与动作选择.docx

上传人:dajiede 2022/7/16 文件大小:24 KB

下载得到文件列表

路由与动作选择.docx

相关文档

文档介绍

文档介绍:【 Web API教程】 动作选择
注:本文是【 Web API系列教程】的一部分,如果您是第一次看本系列 教程,请先看前面的内容。
Routing and Action Selectiolate must match exactly. A placeholder matches any value, unless you specify constraints. The framework does not match other parts of the URI, such as the host name or the query parameters. The framework selects the first route in the route table that matches the URI. 框架会试图把URI路径的片段与该模板进行匹配。模板中的文字必须严格匹配。 占位符可以匹配任意值,除非你指定了约束。框架不会匹配URI的其它部分,如 主机名或查询字符串。框架会选择路由表中与URI匹配的第一条路由。
There are two special placeholders: "(controller}" and "(action}". 有两个特殊的占位符:“{controller} ”和“ {action}”。
"(controller}" provides the name of the controller.
“(controller) ”提供控制器名。
"(action}" provides the name of the action. In Web API, the usual convention is to omit "(action}".
“(action)”提供动作名。在Web API中,通常的约定是忽略“(action)” 的。
Defaults
默认值
If you provide defaults, the route will match a URI that is missing those segments. For example:
如果提供默认值,该路由将能够匹配缺少这些片段的URI。例如:
(
name: "DefaultApi",
routeTemplate: "api/(controller}/(category}",
defaults: new ( category = "all" }
);
The URI "http://localhost/api/products" matches this route. The "(category}" segment is assigned the default value "all".
URI“http://localhost/api/products” 与这条路由是匹配的。"(category)” 片段被赋成了默认值“ all”。
Route Dictionary
路由字典
If the framework finds a match for a URI, it creates a dictionary that contains the value for each placeholder. The keys are the placeholder names, not including the curly values are taken fromthe URI path or from the defaults. The dictionary is stored in the IHttpRouteData object.
如果框架为一个URI找到一个匹配,它会创建一个字典,其中包含了每个占位符 的值。(字典的内容是一些“键-值”对一译者注)。其键是不带花括号的占 位符名称。其值取自URI路径或默认值。该字典被存储在IHttpRouteData对象 中。
During this route-matching phase, the special "(controller}" and "(action}" placeholders are treated just like the other placeholders. They are simply stored in the dictionary with the other values.
在路由匹配阶段,"{controller} ”和“ {action} ”占位符的处理与其它占位符 的处理是一样的。