Member Avatar for CriticalError
CriticalError

so I got two probelms with asp.net 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. http://www.thecodingguys.net < 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 http://www.thecodingguys.net/Tutorials/ASP/WebPages you can get to http://www.thecodingguys.net/Tutorials/ASP/HTML page from that route! How can I stop this?

Second problem is users can still access tutorials from a url like http://www.thecodingguys.net/VBTutorial 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 meeting, networking, learning, and sharing knowledge.