context.MapRoute("authorized-credit-card", "owners/{ownerKey}/authorizedcreditcard/{action}",
new { controller = "authorizedcreditcard", action = "index" },
new { ownerKey = nameFormat }, dataTokens: new { scheme = Uri.UriSchemeHttps });
在我的路线文件中,我有上述路线。
那么,谁能告诉我 dataTokens: new { scheme = Uri.UriSchemeHttps
是什么意思?
以及在 Controller 的操作方法中使用上述dataTokens
?
最佳答案
根据 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.
因此 DataTokens 是一种可以随路由传递的附加数据。预定义了 3 个 DataToken 键(下面的类来自 ASP.NET MVC 4 的源代码,但版本 2 中使用了相同的键):
internal class RouteDataTokenKeys
{
public const string UseNamespaceFallback = "UseNamespaceFallback";
public const string Namespaces = "Namespaces";
public const string Area = "area";
}
我不认为该框架使用名为“scheme”的 DataToken,因此很难回答您的问题。您可能希望在自定义应用程序代码中搜索 DataTokens["scheme"]
并查看需要它的位置和原因。
编辑:
我找到了 an article on "Adding HTTPS/SSL support to ASP.NET MVC routing" .有一个使用“方案”数据 token 的示例。所以我很确定您的应用程序以完全相同的方式使用它。
关于c# - 为什么 dataTokens 在 Route 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16338219/