Skip to content

Setup ASP.NET MVC 3 or ASP.NET MVC 4 project

Simonas Mikulenas edited this page May 24, 2013 · 28 revisions

Prerequisites:

  • ASP.NET MVC 3 or ASP.MVC 4 website project with .Net 4.0

Package installation

In NuGet console paste the line below:

Install-Package BetterCMS

This will install into your website project Better CMS NuGet package and all the dependent packages.

Update Global.asax.cs

After successful Better CMS package installation update your Global.asax.cs file with usings:

using System.Security.Principal;
using BetterCms.Core;
using BetterCms.Core.Environment.Host;

and code:

private static ICmsHost cmsHost;

protected void Application_Start()
{
    cmsHost = CmsContext.RegisterHost();

    /* DO NOT FORGET TO REMOVE DEFAULT ROUTE REGISTRATION! 
       FOLLOWING SOURCE CODE SHOULD BE REMOVED: 

       routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
    */

    // [YOUR CODE]	
		
    cmsHost.OnApplicationStart(this);
}

protected void Application_BeginRequest()
{
    // [YOUR CODE]
	
    cmsHost.OnBeginRequest(this);
}

protected void Application_EndRequest()
{
    // [YOUR CODE]
	
    cmsHost.OnEndRequest(this);
}

protected void Application_Error()
{
    // [YOUR CODE]
	
    cmsHost.OnApplicationError(this);
}

protected void Application_End()
{
    // [YOUR CODE]
	
    cmsHost.OnApplicationEnd(this);
}

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
    // [YOUR CODE]

    // Uncomment following source code for a quick Better CMS test if you don't have implemented users authentication. 
    // Do not use this code for production!
    /*
    var roles = new[] { "BcmsEditContent", "BcmsPublishContent", "BcmsDeleteContent", "BcmsAdministration" };
    var principal = new GenericPrincipal(new GenericIdentity("TestUser"), roles);
    HttpContext.Current.User = principal;
    */

    cmsHost.OnAuthenticateRequest(this);
}

Register Routes

Better CMS add default page with / path - update your site routes configuration not to takeover site root path. Do not forget to remove default route registration, too.

Setup Database

You need only to create database instance and update connection string in Web.config to point to it (use named instance called BetterCms). Accordingly update Config/cms.config tag <database [...]/> with correct information, too. All the necessary database structure (tables and etc.), will be created on application start. The default (if not set) database type is MsSql2008.

  <database
     schemaName="dbo"
     connectionStringName="DefaultConnection"
     databaseType="MsSql2008" >
  </database>

Other availabale DB types: MsSql2000, MsSql2005, Oracle10, Oracle9, PostgreSQL82.

Note: if you have changed database and would like that Better CMS create all the structure in the new one, please delete App_Data/BetterCMS/versions.info file.

Web.config

Update Web.config file:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
    </dependentAssembly>
    [...]
  </assemblyBinding>
</runtime>

Check webpages version (webpages:Version) and disable simple membership provider (enableSimpleMembership) if you not going to use it.

<appSettings>
  <add key="webpages:Version" value="2.0.0.0" />
  <add key="enableSimpleMembership" value="false" />
  [...]
<appSettings>

After all above configuration - CMS is ready for usage.

Clone this wiki locally