Routing 如何忽略果园中的部分路线?

Routing 如何忽略果园中的部分路线?,routing,orchardcms,Routing,Orchardcms,如何设置自定义路由以忽略id之后的所有内容 自动路由似乎是在创建别名并将其保存到数据库时设置别名,因此它不会忽略任何内容,它必须完全匹配。IRouteProvider似乎适用于模块控制器,我希望使用默认的内容控制器 所以基本上,我想创建动作URL,比如 test/{Content.Id}/{Content.Slug} 我想在身份证上匹配,所以 test/{Content.Id} 同时忽略id之后的任何内容,这些内容甚至可能与原始slug不匹配,所以 test/{Content.Id}/wha

如何设置自定义路由以忽略id之后的所有内容

自动路由似乎是在创建别名并将其保存到数据库时设置别名,因此它不会忽略任何内容,它必须完全匹配。IRouteProvider似乎适用于模块控制器,我希望使用默认的内容控制器

所以基本上,我想创建动作URL,比如

test/{Content.Id}/{Content.Slug}
我想在身份证上匹配,所以

test/{Content.Id}
同时忽略id之后的任何内容,这些内容甚至可能与原始slug不匹配,所以

test/{Content.Id}/what/ever/garbage/gets/passed
例如,请查看SO如何管理此url:


同样,我希望使用默认的Orchard内容类型控制器(至少尽可能长)。

您可能必须使用
irouteconsttraint

如果说“内容类型控制器”,您的意思是:零件驱动程序。是不是完全一样。
您可以执行所有必须执行的操作来验证URL,然后调用
\u contentManager.BuildDisplay(contentItem)

我通过在模块中添加Routes类/w以下代码解决了此问题:

public class Routes : IRouteProvider
{
    public void GetRoutes(ICollection<RouteDescriptor> routes)
    {
        var routeDescriptors = GetRoutes();
        foreach (var descriptor in routeDescriptors)
            routes.Add(descriptor);
    }

    public IEnumerable<RouteDescriptor> GetRoutes()
    {
        return new[] {
            new RouteDescriptor {
                Name= "PostIdRoute",
                Route = new Route(
                    "post/{id}/{*SeoFluff}",
                    new RouteValueDictionary{
                        {"area", "Contents"},
                        {"controller", "Item"},
                        {"action", "Display"}
                    },
                    new RouteValueDictionary(),
                    new RouteValueDictionary { {"area", "Contents"} },
                    new MvcRouteHandler()
                )
            }
        };
    }
}
公共类路由:IRouteProvider
{
公共路线(ICollection路线)
{
var routedDescriptors=GetRoutes();
foreach(RoutedDescriptors中的变量描述符)
添加(描述符);
}
公共IEnumerable GetRoutes()
{
返回新的[]{
新路由描述符{
Name=“postidroote”,
路线=新路线(
“post/{id}/{*SeoFluff}”,
新RouteValueDictionary{
{“区域”、“内容”},
{“控制器”,“项目”},
{“动作”,“显示”}
},
新建RouteValueDictionary(),
新的RouteValueDictionary{{“区域”,“内容”},
新的MvcRouteHandler()
)
}
};
}
}
注意“{*SeoFluff}”部分。该通配符是处理未知数量斜杠的关键,如果不包括它,则需要添加多个RoutedDescriptor。

当我说“默认内容类型控制器”时,我指的是内容区域的Orchard.Core.Containers.Controllers.ItemController。