-
Notifications
You must be signed in to change notification settings - Fork 150
Setup ASP.NET MVC 4 project
Prerequisites:
- ASP.NET MVC 4 website project with .Net 4.0
NOTE: this tutorial is available in video format: http://www.youtube.com/watch?v=mHJzmsFPrM4
In NuGet console, paste the line below:
Install-Package BetterCMS
This will install the Better CMS NuGet package and all the dependent packages.
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);
}
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.
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 available DB types: MsSql2000
, MsSql2005
, Oracle10
, Oracle9
, PostgreSQL82
.
Currently only MS Sql Server and Azure is supported.
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.cache
file (this will force CMS to check versions information in database).
Update Web.config file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.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>
Add current line to web.config's system.webServer section (temporary solution). It's required for such files, as main.js
to be loaded correctly:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
After all above configuration - CMS is ready for usage.