Member Avatar

I need some routing help, I am using web pages and I just want to make routing an automated processes.

URLS like this will work


URLs like this will not work:



In the _AppStart I have this code now:

    RouteTable.Routes.MapWebPageRoute("{rcPageName}", "~/Default.cshtml", new {rcPageName = "default" });
    RouteTable.Routes.MapWebPageRoute("tutorials/{cat}/{rcPageName}", "~/Default.cshtml", new{cat = ""});

In the Default.cshtml I have this code:

    //check what page is requested and load data from database
    var pageName = Context.GetRouteValue("rcPageName");
    var routeName = Context.GetRouteValue("cat");   
    if (pageName == null) { pageName = "default"; }

    var db = Database.Open("thecodingguys");
    var selectQueryString = "SELECT pId, pName, pTitle, pText, mTitle, mDescription, mKeywords, pMasterPage, pBody, pEditDate "
                               + "FROM rc_Pages "
                               + "WHERE pName = @0 AND pRouteName=@1";
var data = db.QuerySingle (selectQueryString, pageName, routeName);

If the page does not need a route it is not left blank it has the value "N/A", Basically I have to routes for URLs, but they do not work because I get this error:

Object reference not set to an instance of an object.