Skip to content

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

Simonas Mikulenas edited this page Jan 3, 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 -Pre

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

Update Global.asax.cs

After successful BetterCMS 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 = BetterCmsContext.RegisterHost();
    // [YOUR CODE]
    cmsHost.OnApplicationStart(this);
}
protected void Application_BeginRequest()
{
    cmsHost.OnBeginRequest(this);
}
protected void Application_EndRequest()
{
    cmsHost.OnEndRequest(this);
}
protected void Application_Error()
{
    cmsHost.OnApplicationError(this);
}
protected void Application_End()
{
    cmsHost.OnApplicationEnd(this);
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
    var principal = new GenericPrincipal(new GenericIdentity("TestUser"), new[] { "User", "Admin" });
    HttpContext.Current.User = principal;
}

Register Routes

In RegisterRoutes comment out all route registrations except:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

This is needed because BetterCms by default has a home page in root (this can be changed).

Setup Database

You need only to create database instance and update connectionString to point to it. All the necessary database structure (tables and etc.), will be created on application start.

Web.config

Update Web.config file:

<runtime>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  [...]
</runtime>

Example DB data

After all above configuration - CMS is ready for usage.

Clone this wiki locally