开发者

MVC routing if page url is stored in database

I have kind of CMS application that allows to create content pages and specify urls for them. I'd like to let users enter any url, like:

/Documents/Forms/MyForm
/Documents/Manuals/MyManual
/Events/BBQThisWeek

Then I need to create a route that will check if a content page with the given Url exists in the DB and if yes, will route to controller that handles content pages. If not it'll con开发者_Python百科tinue with default route.

How do I approach this? Thanks V.


You will probable have to set-up a custom handler. Take a look at option three on here

You could read from database on action invoker.


Create a class that extends Route

public class CustomRoute : Route
{

    public override RouteData GetRouteData(System.Web.HttpContextBase httpContext)
    {
        var routeData = base.GetRouteData(httpContext);
        if(routeData != null)
        { do some stuff on routeData... }
        return routeData;
    }

    public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
    {
        // Do the opposite of the first function
    }
}

edit: The easiest way is to extends Route and use base.GetRouteData then just change the data tokens 'controller' and 'action' to what you want

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜