为什么dataTokens是路由? [英] Why dataTokens are in Route?

查看:917
本文介绍了为什么dataTokens是路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 context.MapRoute("authorized-credit-card", "owners/{ownerKey}/authorizedcreditcard/{action}",
 new { controller = "authorizedcreditcard", action = "index" },
 new { ownerKey = nameFormat }, dataTokens: new { scheme = Uri.UriSchemeHttps });

在我的路由文件我有一种以上的干线

In my route file I am having above kind of Route.

所以,可以在任何一个可以告诉我什么是 dataTokens的含义是:?新{方案= Uri.UriSchemeHttps

So, could any one tell me what is the meaning of dataTokens: new { scheme = Uri.UriSchemeHttps ?

和控制器的操作方法内上述 dataTokens 的使用情况如何?

And usage of above dataTokens inside the controller's action method ?

推荐答案

据的文档

您使用DataTokens属性检索或分配与不用于确定路由是否一个URL模式相匹配的路由相关的值。这些数值被传递给路由处理,在那里他们可用于处理请求

You use the DataTokens property to retrieve or assign values associated with the route that are not used to determine whether a route matches a URL pattern. These values are passed to the route handler, where they can be used for processing the request.

所以DataTokens是一种可与路线传递的附加数据的。有3 DataToken的键是predefined(类下面来ASP.NET MVC 4,但相同的密钥的形式源$ C ​​$ C版本2时):

So DataTokens is kind of additional data which can be passed with the route. There are 3 DataToken's keys being predefined (the class below comes form source code of ASP.NET MVC 4 but the same keys are used in version 2):

internal class RouteDataTokenKeys
{
    public const string UseNamespaceFallback = "UseNamespaceFallback";
    public const string Namespaces = "Namespaces";
    public const string Area = "area";
}

我不认为框架使用DataToken命名为计划,所以就很难回答你的问题。您可能想要搜索的自定义应用程序code为 DataTokens [方案] ,看看,为什么它是需要的。

I don't think the framework uses DataToken named "scheme" so it is difficult to answer your question. You may want to search your custom application code for DataTokens["scheme"] and see where and why it is needed.

编辑:

我发现上的添加HTTPS的文章/到ASP.NET MVC路由 SSL支持。有使用计划数据令牌的例子。所以我pretty确保您的应用程序使用它非常相同的方式。

I've found an article on "Adding HTTPS/SSL support to ASP.NET MVC routing". There is an example of using "scheme" data token. So I'm pretty sure that your application uses it in the very same way.

这篇关于为什么dataTokens是路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆