问题
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