制作先进的MVC路线

时间:2016-08-09 07:57:04

标签: asp.net-mvc asp.net-mvc-routing

我的网站包含两个主要的动态模块:

1-模块(1):为了使网站管理员能够管理整个网站页面的静态内容,他可以将父页面和子项添加到2个级别

2-模块(2):使网站管理员能够管理应发布到网站的新闻文章

对于路由,我们计划如下:

1-模块(1)

www.websitename.com/parentpage

www.websitename.com/parentpage/childpage

www.websitename.com/parentpage/childpage/childchildpage

2-模块(2)

www.websitename.com/news/newstitle

这里的问题是模块(2)路由未被处理或执行。我认为因为它与模块(1)中的第二个场景存在冲突。

有任何建议或建议吗?

最诚挚的问候,

黑幕

1 个答案:

答案 0 :(得分:0)

感谢您的帮助。我使用RouteBase

解决了这个问题
 public class MyUrlRoute : RouteBase
{
    public override RouteData GetRouteData(HttpContextBase httpContext)
    {
        //Route Code
    }

    public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
    {
        //Virtual Path Code
    }
}

在RouteConfig中

public static void RegisterRoutes(RouteCollection routes)
{
    routes.Add(new MyUrlRoute()); // Add before your default Routes
    defaults: new { language = "en", controller = "Home", action = "Home" },
    namespaces: new string[] { "Solution.Website.Controllers" }
    );
}