- ASP.NET 4.51, MVC 5
- Have read Integrating a CMS into an established application-centric MVC website
We have a number of MVC applications that serve as public facing websites. The applications were built using MVC as that was the technology stack understood by the developers and primarily the content that was being delivered was based on business process data.
However more and more we are being asked to add “another page” to the websites which for all intents and purposes is a plain old static content page. This ultimately involves:
- Adding a new route
- Creating a view with the required HTML
We have various “home grown” solutions which now pull HTML from the database for these views. However this means we are writing custom back end data entry screens as well as 1 & 2 above.
So…. There must be a better way. Has anyone got any practical experience or suggestions on how to add simple CMS functionality that we can give to end users, plugged into our MVC application? We need to provide the following functionality to the end user:
- Create new pages, edit pages using WYSIWYG
- Add meta tags and canonical tags for SEO
- Specify the url portion of the uri for SEO purposes
All insights appreciated.
2
Answers
Is it feasible to do the following:
Have a database table to house the content for these pages. e.g. title, summary, description, url, meta, image(s) etc…
In the front end have a template for these pages. The database data fills in the placeholders within this template.
Perhaps hold all the pages on a base URL like http://www.yoursite.com/page/
dynamic-page-url-from-db
You can use the
Remote
attribute validation on theurl
field to make sure they are all unique in the database.With this in mind, create a single Route to catch the requests and filter valid/invalid requests in the
Page
controller based on the URL provided with the db. If non-existentthrow new HttpException(404, "Page Not Found");
and have an error handler pick that up and deliver your 404.META could be set via
ViewBag
or a dedicatedsection
that alters the_Layout
file at the point of rendering the view.TinyMCE is a decent WYSIWYG editor. You can even add dynamic image gallery functionality to it if you want to embed images within the main body of the pages.
I’m working on making a CMS currently used in a demanding production environment into a product. I’ve just (as of 20 Jan 2015) made a NuGet package which installs the CMS into an MVC project which should be possible to add to any existing MVC site without breaking it. CMS functionality can then be added where needed. Currently I’m looking to work with some users to help them get the CMS into production on their sites, however this may have changed by the time you read this. Look at http://www.lynicon.com for more information and to sign up to a Slack community where I can give you access to the NuGet package.