Why are dataTokens 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 have a route view.

So, can someone tell me what dataTokens: new { scheme = Uri.UriSchemeHttps means dataTokens: new { scheme = Uri.UriSchemeHttps ?

And using above dataTokens inside controller action method?

+6
source share
1 answer

According to the documentation :

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

So, DataTokens are additional data that can be transmitted using the route. There are 3 DataToken keys that are predefined (the following is the following ASP.NET MVC 4 source code class, 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 do not think that the structure uses a DataToken with the name "schema", so it is difficult to answer your question. You can find your application code for DataTokens["scheme"] and see where and why it is needed.

EDIT:

I found the article “Adding HTTPS / SSL Support for ASP.NET MVC Routing” . There is an example of using a schema data token. Therefore, I am sure your application uses it in the same way.

+7
source

Source: https://habr.com/ru/post/944116/


All Articles