views:

59

answers:

2

I'm working on a mini CMS-like application using asp.net MVC 1.0 (I will upgrade it once 2.0 is released). Once feature I want, that is pretty vital to a CMS, is the ability for an admin to add pages to their site.

Essentially, if the admin wants to add a page called "Links", I want them to be able to do so without having to go through any of the hassle of adding the action to the controller and compiling a new assembly.

I have an idea for a solution and I want to know what the community thinks.

I think that I should write a class called (for arguments sake let's call it UserGeneratedGenericController) that extends the Controller class. In this class, I will have a single Action that reads a parameter and redirects to the View that corresponds with the parameter passed to the action.

I will also have to edit the Routing in the Global.asax.cs file

therefore /UserGeneratedGenericController/Links will hit the same Action that /UserGeneratedGenericController/News will hit, but will display the views as desired.

What say you? I'm interested in your comments on this approach and your suggestions to other approaches.

A: 

You want to take the page title, and create a unique url slug for it, then you want to be able to load the content from the database based on the url slug (using the url slug as the id, rather than an actual database id).

public ActionResult Index(string UrlSlug) {
  // Get Content For Page {UrlSlug}
}

So your route would be /Pages/{UrlSlug} and a sample would be /Pages/Links. Then your Index action on your PagesController would pull off the url slug (Links) and load the appropriate content from storage, and render the content inside your master layout. I think you were thinking along these lines, just make sure when the user adds a page, you create a unique url for it. Replace spaces with underscores, remove special characters, etc to create a url safe key to use to load the page information when it is requested.

NerdFury
I think his own suggestion already uses this approach.
Martijn Laarman
Martijn is correct, that was my proposed solution. I am looking for comments on this solution or other suggestions
splatto
True, it does, but the author wants community feedback, and in the CRM world, there are strategies for handling this. The idea of the url slug makes things more obvious, and uses a term common to this domain. Now the author can feel comformatable that the approach is acceptable, and learns some common terminology.
NerdFury
My comments are, this is the most common, and accepted practice. There are different ways of handling the slugs, and that would be a different problem. StackOverflow combines the id and title. Other sites just use the title. If two pages have the same title, then you may want to resort to appending numbers. Once the slug is created, you have to decide if you want it if the page title is edited. Usually you would want to keep the slug the same, even if the title changes so that you don't break links to the pages.
NerdFury
A: 

i think what you presented is the way to go