Member Avatar

so I got two probelms with routing, I got these these routing values in my _AppStart

   RouteTable.Routes.MapWebPageRoute("{rcPageName}", "~/Default.cshtml", new { rcPageName = "default"});
    RouteTable.Routes.MapWebPageRoute("Tutorials/PHP/{rcPageName}", "~/Default.cshtml", new { rcPageName = "PHPTutorial"});
    RouteTable.Routes.MapWebPageRoute("Tutorials/VB/{rcPageName}", "~/Default.cshtml", new { rcPageName = "VBTutorial" });
    RouteTable.Routes.MapWebPageRoute("Tutorials/CSharp/{rcPageName}", "~/Default.cshtml", new { rcPageName = "C-SharpTutorial" });
    RouteTable.Routes.MapWebPageRoute("Tutorials/HTML/{rcPageName}", "~/Default.cshtml", new { rcPageName = "HTMLTutorial" });
    RouteTable.Routes.MapWebPageRoute("Tutorials/CSS/{rcPageName}", "~/Default.cshtml", new { rcPageName = "CSSTutorial" });
    RouteTable.Routes.MapWebPageRoute("Tutorials/ASP/{rcPageName}", "~/Default.cshtml", new { rcPageName = "WebPages" });

Now they all go to the Default.cshtml page which basically requests the page (or row) from the database. and prints it out. < as you can see

Here is the getroutevalue in the Default.cshtml page

   var pageName = Context.GetRouteValue("rcPageName");
    if (pageName == null) { pageName = "default"; }

Now the problem is that if you go to my website above, people can still access other pages from different routes so if you go to you can get to page from that route! How can I stop this?

Second problem is users can still access tutorials from a url like how can I stop this and redirect the correct route?

I tried to use constraints but that never works gives error and points to this line in the Default.cshtml file:

var data = db.QuerySingle (selectQueryString, pageName);

Says something like it requires another value.

Any help?

Be a part of the DaniWeb community

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