Member Avatar for CriticalError

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

URLS like this will work

http://localhost:24/tutorials/visualbasic/vb-select-case

URLs like this will not work:

http://localhost:24/sitemap

http://localhost:24

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.