What’s New in Better CMS

“We can build a better content management system” is a statement every web developer has said at least once in their career. It’s an elusive, romantic goal that originates from a wish to make it easier for clients to publish content. Well, call us romantics but we’ve done just that. We’ve made that statement close to five times (or versions) now, with roots going back five years to when we were an organization of only five. Better CMS is the result of many lessons learned.

But let’s start from the beginning for folks who are hearing about us for the first time. Ambitious, passionate, but perhaps a little understaffed and inexperienced we were. Tens of thousands of mystical man hours later, at the five year anniversary of our organization, we are proud to present the Better CMS v1.3.0. Originally a paid product, today the open source Better CMS fills an industry gap on the .NET platform.

Better CMS was born from Devbridge Group - we have a great dedicated team here:

Tomas K. Architect

Paulius M. Architect

Adomas UX\Design

Lingaile UX\Design

Audrunas Web Developer

Darius Web Developer

Paulius G. Web Developer

Simonas Web Developer

Daiva Quality Assurance

Beyond our dedicated team, Better CMS is an open source project and we accept external pull requests.

And so it is an excellent time to introduce the new features we just released on Better CMS. You can grab the latest version from nuget.org, try a live demo or explore the documentation and source code on GitHub. You can also view the full list of release notes.

Introduction

Better CMS is a publishing focused and developer friendly .NET Open Source CMS. It is a modular ASP.NET MVC subsystem created to intercorporate into web applications gently and transparently. Better CMS has an intuitive user interface designed to help you make updates to your website content and SEO settings quickly and efficiently.

When you login, you will see a Better CMS menu on the left side of your screen. This side menu contains all of the controls you’ll need to make changes to your website. Better CMS features on-page editing. This enables a user to edit a content on the web page and see exactly what it will look like when the page is live. All of the tools you will need to make changes to your website are located in the side menu. A regular screen when you are connected will look like this:

CMS Menu and all dialogs are explained in details in the project wiki.

How to install Better CMS?

In order to install Better CMS your project should meet the following pre-requisites:
- ASP.NET MVC 3 or ASP.MVC 4 website project.
- .NET 4.0 or .NET 4.5 Framework
- Razor View Engine

You should open or create a new project with Visual Studio and in the package manager console type the line below:

PM> Install-Package BetterCMS

This will install Better CMS into your project. The next steps are:
- Create database if it doesn't exists. Currently Better CMS supports SQL Server 2005/2008/2012 and SQL Azure databases.
- Update a Global.asax.cs file to run CmsHost on application start.
- Update web.config files and cms.config. All required tables will be created during application startup.
- Important! Remove default route registration {controller}\{action}\{id} - as it would override Better CMS routes handler and you will not be able to access CMS pages.

All instructions and details on how to install Better CMS can be found on Github.

Modules overview

Better CMS has a modular architecture. The core logic is placed in the core library when all other client/server side logic is decoupled into modules.

Default modules are packed-in in the Better CMS:
- BetterCms.Core library - adds general logic and handles modules registration.
- BetterCms.Module.Root module - adds page rendering engine. Handles sidebar and site settings dialogs.
- BetterCms.Module.Pages module - adds extended page properties and UI views to handle page properties and SEO.
- BetterCms.Module.MediaManager module - adds images and files handling logic and UI views.
- BetterCms.Module.Blog module - adds blogging engine logic and UI views.
- BetterCms.Module.Installation module - contains a Better CMS installation logic.

All other modules are optional. Let’s explore them:
- CMS BetterCms.Module.API module - in order to access internal CMS data from source code like page properties, media files, tags, categories and so on you should install this module.
- CMS BetterCms.Module.API.Web module - adds HTTP listener for Better CMS API. After this module installation you will be able to access internal CMS data over HTTP.
- CMS BetterCms.Module.Users module - adds users and roles management functionality. Handles login/logout actions.
- CMS BetterCms.Module.Users.Api module - extends Better CMS API module with users and roles access methods.
- BetterCms.Module.AppFabricCache module - adds Better CMS caching service implementation to cache data in the Windows Server AppFabric Caching cluster.
- BetterCms.Module.WindowsAzureStorage module - adds Better CMS storage implementation to store images and files in the Windows Azure cloud storage.
- BetterCms.Module.AmazonS3Storage module - adds Better CMS storage implementation to store images and files in the Amazon S3 cloud storage. Better CMS storage configuration documentation is here.

How to configure Users module correctly

First you need to install Users module:

PM> Install-Package BetterCMS.Module.Users

In the cms.config file you should add section if it doesn't exist:

<users createdefaultuseronstart="true" enablecmsformsauthentication="true"></users>

  • createDefaultUserOnStart: boolean. If set to true, Better CMS checks if any user exists when it starts for the first time. If not, user registration form is opened to create administrator.
  • enableCmsFormsAuthentication: boolean. If set to true, routes /login and /logout are registered and user login form is provided.

In the web.config file you should:

  1. set authentication mode to Forms:
    <authentication mode="Forms">
       <forms loginUrl="/login" defaultUrl="/" />
    </authentication>
    
  2. add roleManager provider:
    <roleManager enabled="true" defaultProvider="BetterCmsRoleProvider" cacheRolesInCookie="true">
       <providers>
         <clear />
         <add name="BetterCmsRoleProvider" type="BetterCms.Module.Users.Provider.CmsRoleProvider" />
       </providers>
    </roleManager>
    
  3. add membership provider:
    <membership defaultProvider="CmsMembershipProvider">
       <providers>
         <clear />
         <add name="CmsMembershipProvider" type="BetterCms.Module.Users.Provider.CmsMembershipProvider" />
       </providers>
    </membership>
    

That’s it - now on the first run Better CMS will ask to create administrator account and /login form will appear.

How to access Better CMS data programmatically

First you need to install Better CMS API module:

PM> Install-Package BetterCMS.Module.Api

With BetterCms.Module.Api module installed you can access Better CMS internal data. Check out the code sample below to get an idea of how easy it is to access CMS data programmatically:

private void GetAllTagsAndPageByUrlApiDemo()
{
    using (var api = ApiFactory.Create())
    {
        var allTags = api.Root.Tags.Get(new GetTagsRequest());

        var page = api.Pages.Page.Get(new GetPageRequest
        {
            PageUrl = "/demo-page/"
        });
    }
}

The first and very important thing that you should handle is the API object lifecycle to avoid connection leaks. The best way to do so is to wrap API object into using statement. In given example we are going to retrieve all existing tags and page with URL /demo-page/.

Add Better CMS Web API endpoint

To expose Better CMS API operation via Web you need to install a BetterCms.Module.Api.Web package:

PM> Install-Package BetterCMS.Module.Api.Web

​​After this package installation you should see in the web.config file new section:

<location path="bcms-api">
  <!-- Required for IIS 7.0 -->
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
</location>

Now you can navigate with a browser to link http://[your application]/bcms-api/ and you should see screen like this:

This is a list of all available operations in Better CMS API. View documentation for all operations. Currently we support only GET operations, but in the future releases we are going to implement POST/PUT/DELETE operations too.

Here is an example how to access Better CMS API with jQuery Ajax call:

(function() {
    var options = {
        type: 'GET',
        contentType: 'application/json',
        dataType: 'json',
        success: function(result) {
            console.log('Total Tags count starting with 'Demo-':' + result.data.items.length);
        }        
    };

    var data = {
        filter: {
            where: [
                { field: 'Name', operation: 'StartsWith', value: 'Demo-' }
            ]
        },
        order: {
            by: [
                { field: 'Name' }
            ]
        },
        skip: 2,
        take: 5
    };

    options.data = "data=" + JSON.stringify(data);

    $.ajax('/bcms-api/tags/', options);
}());

Recommendation - it is recommended to deploy BetterCms.Module.Api.Web as a separate web site to run it under separate application pool as you don’t want to have direct relation between API and Web requests handling.

How to protect pages and content

Starting from version 1.3 it is possible to enable access control for pages and files to protect them from unauthorized access.

In cms.config you will find security section:

<security accessControlEnabled="true" fullAccessRoles="Owner" encryptionEnabled="false" encryptionKey="bettercmstest">
    <defaultAccessRules defaultAccessLevel="ReadWrite">
        <add identity="Everyone" accessLevel="Deny" isRole="true" />
        <add identity="Authenticated Users" accessLevel="Read" isRole="true" />
    </defaultAccessRules>
</security>

Security section explained:

  • accessControlEnabled: indicates, if access control security is enabled. Default value: false.
  • fullAccessRoles: string. Role name(s), which will have full access. Default value: Owner.
  • encryptionEnabled: boolean. Determines, if HTML content encryption is enabled. If set to true, HTML contents and HTML widgets contents are encrypted using encryptionKey key. Default value is false.
  • encryptionKey: string. If encryptionEnabled is set to true, this key is used to encrypt/decrypt content.

defaultAccessRules configuration section attributes:

  • defaultAccessLevel: string. Possible values: ReadWrite, Read, Deny. Default value: ReadWrite. Defines default access level for object with no access rules when access control is enabled.

defaultAccessRules is a list of default users and roles rules for new pages and files:

  • identity: string. User or role name.
  • accessLevel: string. Possible values: ReadWrite, Read, Deny. Default value: ReadWrite.
  • isRole: boolean. Indicates, if identity is user, or role.

 Now if access control is enabled in pages and files dialogs you will find below section:

You will be able to add or remove any role or user and protect your resources in unique way.

Conclusion

That’s all folks! We reviewed new modules and features released in the 1.3.0 version. Feel free to ask or suggest any ideas via http://www.bettercms.com/support/ or contact us directly via email info@bettercms.com.

comments powered by Disqus