Im trying to make a very simple application that lets my client create their own pages.
The hard part is to let them create thir own URL.
Client need to fill in:
- Page name (ex. About us).
- Page description (ex. We are a big company).
- Page URL relative (ex. /About)
When client enter this information and save, it should be saved in the database.
I can easily create a controller named “Page” which takes a value “ID” and when a user enters “www.someurl.com/Page/1” the newly created page pops up.
But what I really want is for the user to write “www.someurl.com/About” and then the page pops up.
How can this be done with some kind of dynamic rewrite/route code using ASP MVC.
My idea would be to create a field in your ‘Page’ table called ‘Slug.’ When your user creates a new page they would have to fill out the ‘Slug’ field and enter what they would like to see in the url (ex: page wanted – “About”, slug – “about” | page wanted – “See Our Sponsors”, slug – “see-our-sponsors” | etc). You can automate this process with a little bit of javascript if you want.
Create a route like so:
Create an action method like so:
Basically it would work like your idea of putting the page id in the url but it would be much cleaner and it would use ‘slug’ to do the database lookup instead of the page id.