asp.net 核心路由 - 获取包含斜杠的 URL 参数

asp.net core routing - get URL parameters that include slashes

是否可以在 asp.net 核心中有一个路由 returns URL 的整个路径作为我的 IActionResult 的变量。

例如:

  1. 对于https://example.com/servicespath变量应该相等 到 "services"
  2. 对于https://example.com/services/cleaningpath变量应该 等于 "services/cleaning"
  3. 对于https://example.com/services/paintingpath变量应该 等于 "services/painting"
  4. 对于https://example.com/services/painting/interior路径变量应该 等于 "services/painting/interior"

我的 Startup.cs

中只有以下路线
app.UseMvc(routes =>
{
    routes.MapRoute(
        "Redirect",
        "{*path}",
        new { controller = "Home", action = "Index", path = string.Empty }
    );
});

这适用于示例 1,但对于示例 2、3 和 4 将被忽略。

无论斜杠的数量如何,我怎样才能找到工作路线?


更新: 我的问题是我用路由定义装饰了我的控制器。我删除了它,一切正常。

我的问题是我用路由定义装饰了我的控制器。我删除了它,一切正常。