c# - 为什么 dataTokens 在 Route 中?

标签 c# asp.net-mvc-2 routes

 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/

相关文章:

asp.net-mvc-2 - 在 MVC 2 中设置文本框的属性并对其进行格式化

javascript - slim 的路线给了我 404

algorithm - 沿着兴趣点寻找路线

asp.net-mvc - 漏洞?即使没有错误,ASP.NET MVC 2 中的客户端验证也会导致显示 ValidationSummary 消息

ruby-on-rails - 如何处理自定义 url 中的大写和小写字符?

C# 改变按钮的背景颜色

C# 计时器在 X 秒后关闭控制台窗口

c# - 使用 LINQ 联合两个嵌套 List<object>

c# - 如何在 MEF 中使用事件聚合器?

html - 试图将我的图像定位得低一点,但它会把所有东西都拖下来