-
Notifications
You must be signed in to change notification settings - Fork 148
Setup ASP.NET MVC 3 or ASP.NET MVC 4 project
Prerequisites:
- ASP.NET MVC 3 or ASP.MVC 4 website project with .Net 4.0
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.
After successful BetterCMS package installation update your Global.asax.cs file with usings:
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;
}
In RegisterRoutes comment out all route registrations except:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
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.
Update Web.config file:
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" requirePermission="false" />
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" requirePermission="false" />
</sectionGroup>
<section name="cms" type="BetterCms.Configuration.CmsConfigurationSection, BetterCms.Configuration" requirePermission="false" />
</configSections>
<connectionStrings configSource="Config\connectionStrings.config" />
<cms configSource="Config\cms.config" />
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog">
<arg key="configType" value="FILE" />
<arg key="configFile" value="~/Config/nlog.config" />
</factoryAdapter>
</logging>
</common>
<runtime>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
[...]
</runtime>
Create Config folder in your project and add configuration files:
Config \ connectionStrings.config:
<?xml version="1.0"?>
<connectionStrings>
<add name="BetterCms" connectionString="Server=(local);Database=BetterCms;Integrated Security=SSPI;" />
</connectionStrings>
Config \ cms.config:
<?xml version="1.0"?>
<cms controlerPath="/cms/"
loginUrl="/?returnUrl={returnUrl}"
resourcesRoot="/Content/Resources/"
pageNotFoundUrl="/404/"
workingDirectoryRootPath="~/App_Data/BetterCms"
defaultImageWidth="550"
cmsDevEnv="true"
pageCheckoutEnabled="true"
enforcePermissions="true">
<urlPatterns>
<add expression="^[0-9a-z-/]+$" description="Path can contain only following characters: '0-9', 'a-z', '-', '/'" />
<add expression="^/" description="Path must start with forward flash: /" />
<add expression="/$" description="Path must end with forward flash: /" />
<add expression="^/(cms|bin)/" negate="true" description="Url can not have these as first directory: cms, local, bin" />
</urlPatterns>
<menuSections>
<section name="Custom Links">
<links>
<link name="Home" url="/" />
<link name="Documentation" url="/documentation/" />
</links>
</section>
</menuSections>
<storage serviceType="FileSystem" contentRoot="~/uploads/" contentRootUrl="http://bettercms.local/uploads" />
<!--<storage serviceType="Ftp" contentRoot="[images root]">
<add key="FtpRoot" value="[ftp root]" />
<add key="FtpUserName" value="[ftp user name]" />
<add key="FtpPassword" value="[ftp password]" />
</storage>
<storage serviceType="AmazonS3" contentRoot="[images root]">
<add key="AmazonAccessKey" value="[your access key]" />
<add key="AmazonSecretKey" value="[your secret key]" />
<add key="AmazonBucketName" value="[your bucket name]" />
</storage>-->
<cache enabled="true" timeout="00:10:00" cacheType="HttpRuntime" />
<!-- <cache enabled="true" timeout="00:10:00" cacheType="Auto" />
<cache enabled="true" timeout="00:10:00" cacheType="Custom">
<add key="typeName" value="BetterCms.Sandbox.Mvc4.Custom.CustomCacheTest, BetterCms.Sandbox.Mvc4" />
</cache> -->
<database
schemaName="dbo"
connectionStringName="BetterCms">
</database>
<security
contentManagementRoles="Admin,User"
contentPublishingRoles="Admin"
pagePublishingRoles="Admin">
</security>
<moduleGallery
feedUrl="http://mynugetfeed.com/nuget">
</moduleGallery>
</cms>
Config \ nlog.config:
<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="console" xsi:type="Console" layout="${date:format=HH:MM:ss} ${logger} ${message}" />
<target name="sql_to_file" xsi:type="File" fileName="${basedir}/logs/bettercms-sql.log" archiveFileName="${basedir}/logs/sql_log_${shortdate}_{#####}.log" layout="${longdate} ${message}${newline}${exception:format=message,tostring:maxInnerExceptionLevel=10:innerFormat=message,tostring}" concurrentWrites="true" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="100" />
<target name="log_file" xsi:type="File" fileName="${basedir}/logs/bettercms.log" archiveFileName="${basedir}/logs/error_log_${shortdate}_{#####}.log" layout="${longdate} ${message}${newline}${exception:format=message,tostring:maxInnerExceptionLevel=10:innerFormat=message,tostring}" concurrentWrites="true" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="100" />
</targets>
<rules>
<logger name="NHibernate.SQL" writeTo="sql_to_file" minlevel="Debug" />
<logger name="*" writeTo="log_file" minlevel="Trace" maxlevel="Fatal" />
</rules>
</nlog>
In web site project add reference to:
..\packages\FluentMigrator.1.0.3.0\tools\FluentMigrator.Runner.dll
After all above configuration - CMS is ready for usage, but if you would like to have some demo data import below script to database.