Why dataTokens are in Route?

我只是一个虾纸丫 提交于 2019-12-04 03:12:29

问题


 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.

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

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


回答1:


According to the documentation:

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.

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";
}

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.

EDIT:

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.



来源:https://stackoverflow.com/questions/16338219/why-datatokens-are-in-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!