如何从路由表中删除路由
本文关键字:路由 删除 | 更新日期: 2023-09-27 18:31:51
我正在尝试从路由表中删除路由。我的代码是:
var pages = from v in db.tblCmsPages where v.IsActive select v.PageUrlName;
foreach (string row in pages)
{
routes.MapRoute(
name: "mypages_"+row,
url: row,
defaults: new { controller = "MyPages", action = "en" },
namespaces: new[] { "MGP_RealState.Controllers" }
);
}
这是我的路线集合。我只想从此集合中删除特定路线。我尝试使用 linq 选择特定路由,就像
var myrouter = from v in System.Web.Routing.RouteTable.Routes where v.? select v
不工作
System.Web.Routing.RouteTable.Routes.Remove(?);
只是我们需要创建一个路由对象。
//Create the object of particular router
var rr = new System.Web.Routing.Route(tblcmspage.PageUrlName, new MvcRouteHandler())
{
Defaults = new System.Web.Routing.RouteValueDictionary(new { controller = "MyPages", action = "en" }),
DataTokens = new System.Web.Routing.RouteValueDictionary(new { namespaces = new[] { "MGP_RealState.Controllers" } })
};
//delete the router
System.Web.Routing.RouteTable.Routes.Remove(rr);