Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why dataTokens are in Route?

 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 ?

like image 260
Sampath Avatar asked May 02 '13 12:05

Sampath


People also ask

What is Datatokens?

Datatokens are ERC20 tokens that represent both the value of the data asset and provide the access control to the data asset.

What is RouteData dataTokens?

The data tokens that are associated with a route are initialized when a route maps an incoming URL to an action method. Once these data tokens have been set, you can access them from your action method using the RouteData. Tokens property. This property exposes the data tokens as a collection of key-value pairs.

What is route data ASP net Core?

Routing is responsible for matching incoming HTTP requests and dispatching those requests to the app's executable endpoints. Endpoints are the app's units of executable request-handling code. Endpoints are defined in the app and configured when the app starts.

What is the correct way to define route token in Web API core?

NET Core framework known as Route token. The token [controller] replaces the values of the controller name from the action or class where the route is defined. Here controller name is Values decorated by Route Controller token, [Route("api/[controller]")]


1 Answers

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.

like image 161
Lukasz Lysik Avatar answered Sep 28 '22 12:09

Lukasz Lysik