-1

Am trying to build a CMS, where I need only two views on Front-End of the Website, and it should be like

//localhost/  => Should be Index / Home Page

//localhost/any-main-page1
//localhost/any-main-page2
.
.
//localhost/any-main-pageN


//localhost/any-main-page1?{any-length-query-string}

//localhost/any-main-page1/any-sub-page1

//localhost/any-main-page1/any-sub-pag1e?{any-length-query-string}

There is no limit for main-page and sub-page or sub-sub-pages

And requirement is for any sub-page it can be any number of sub-sub-pages, minimum 3 levels, max it can be anything.

I tried with path.js, it's coming out # in address bar, which will be not be pure SEO friendly :(

I tried with "SlugRouteHandler()" but its not solving in all conditions.

I really need URL to load from Database, because admin will create all the Main & Sub-pages

Database:

MenuTable

seourl is the column-name and data is: home, about-us, services. services/web, services/marketing etc., etc.,

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Is there any way to solve this routing issue? – Saheel Ahmed Apr 03 '14 at 11:57
  • What does "no limit for main page and sub page or sub sub pages" mean? Does this mean that the names of the pages themselves are unlimited? Or that you can have unlimited segments in the URL? – George Stocker Apr 03 '14 at 12:07
  • Exactly! you are right – Saheel Ahmed Apr 03 '14 at 12:15
  • I'm not sure about MVC routing, but this seems like it would be pretty simple in IIS Url Rewrite (http://www.iis.net/downloads/microsoft/url-rewrite). Maybe researching the way they do it could help you out. – L_7337 Apr 03 '14 at 12:18

1 Answers1

0

It's not just a 'routing issue' you have on your hands. You need a solution that spans all three tiers:

  • Routing and name resolution
  • Unique naming and slugifying names
  • Storing this in the Database

Each part really is its own separate piece, but your problem will only be solved by solving each of the three.

This is an extremely broad question; To help you further we'd need:

  • The table structure OR the class structure and what a sample object pulled back from the database would look like
  • The constraints on the names -- is each 'main page' name guaranteed unique? Is every sub-page for a given main page guaranteed unique? Is every sub sub page for a given sub page guaranteed unique? You get the idea.

If your problem is specifically in Routing alone, here's a route that would handle it, and a controller that would handle the route:

routes.MapRoute("Page Resolution",
    "{mainPage}/{subPage}/{subSubPage}",
    new {controller = "PageController", action = "Page" }
);

routes.MapRoute("Page Resolution",
    "{mainPage}/{subPage}",
    new {controller = "PageController", action = "Page" }
);

routes.MapRoute("Page Resolution",
    "{mainpage}",
    new {controller = "PageController", action = "Page" }
);

Controller

public ActionResult Page(string mainPage, string subPage, string subSubPage) 
{
    var pageRepository = new PageRepository(); //simplified. Don't do this in actual code
    var page = pageRepository.GetPage(mainPage, subPage, subSubPage);
    var pageViewModel = new PageViewModel(page);
    return View(pageViewModel); 
}

The code in the repository could handle the overloads to look for a page that doesn't have a sub page or sub sub page.

The code above is simplified because you haven't shown us any code yet that would help me specify. In this case, I've elected to let the repository layer handle what happens if any of those values are String.Empty; and since I don't know what your data retrieval mechanism is, I can't go further (SQLDataClient, LinqToSql, Entity Framework, NHibernate, etc).

I'm also making the assumption that prettifying and slugifying the URLs are done in accordance with one of the other Stack Overflow questions on the subject.

As a general solution, here are three Stack Overflow questions that solve the different problems you actually have:

Community
  • 1
  • 1
George Stocker
  • 57,289
  • 29
  • 176
  • 237
  • Yes George! in my database all are Unique – Saheel Ahmed Apr 03 '14 at 12:17
  • @SaheelAhmed You should update your question with the problems I pose in my solution, as well as which part of this issue you want us to solve; as it stands now I could write a book on what you need to do. We need to see your code so we can narrow down the problem. Is your problem in storing? Is your problem in retrieving? Is your problem in URL resolution? If it's just in the last part (routing), then we need to see some of the objects retrieved from the db that have the URL segments in them as well as what they look like and what specifically differentiates them. – George Stocker Apr 03 '14 at 12:19
  • routes.MapRoute( name: "CmsRoute", url: "{*permalink}", defaults: new { controller = "Page", action = "Index" } ); @George, can this solve my problem ? – Saheel Ahmed Apr 04 '14 at 04:25
  • http://stackoverflow.com/questions/16026441/dynamic-routes-from-database-for-asp-net-mvc-cms – Saheel Ahmed Apr 04 '14 at 05:19