2

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 continue with default route.

How do I approach this? Thanks V.

tereško
  • 58,060
  • 25
  • 98
  • 150
xirurg
  • 35
  • 3

2 Answers2

0

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.

Community
  • 1
  • 1
Richard Forrest
  • 3,567
  • 2
  • 23
  • 32
0

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

Guillaume86
  • 14,341
  • 4
  • 53
  • 53