< back

Configure StoreBuilder with new ASP.NET MVC Project

Step 1 - Create a new MVC Project

Step 2 - Add StoreBuilder Nuget Packages

  • StoreBuilder
  • StoreBuilder.Log4net
  • StoreBuilder.Mvc
  • StoreBuilder.AspNetMembership

Optionally:

  • StoreBuilder.Admin

Step 3 - Configure StoreBuilder to use AspNetMembership security provider for authentication

Add StoreBuilder section to your web project's web.config file.

<storefront>
  <database connectionStringName="Storefront" />
  <logProvider type="StoreBuilder.Log4Net.LogProvider, StoreBuilder.Log4Net" />
  <securityProvider type="StoreBuilder.AspNetMembership.IdentitySecurityProvider,type="StoreBuilder.AspNetMembership.AspNetMembershipSecurityProvider, StoreBuilder.AspNetMembership" />
  <license accountKey="25RD-V3QU-NA56-PGQY" licenseKey="AAAA-AQA5-CGL2-CZCR-3Y7W-V5ZW-UU2N-73FY-YHUO-TWZO-NRMP-SLXD-FOEU-LN7W-JJLZ-LC4S-BEPY-RXND" />
</storefront>

If you remove the logProvider configuration element, you will simply have no logging configured but StoreBuilder will run fine.

Step 4 - Hook in StoreBuilder routing for MVC

Edit the default RouteConfig.cs file generated by the MVC project temlpate and add the following line as the last route table entry:

routes.Add(new StoreBuilderRouteProcessor("{*catchAll}", new MvcRouteHandler()));

This effectively passes on all unhandled routes to StoreBuilder for processing. StoreBuilder will then internally resolve ecommerce related routes as well as handle any 404 not found routes.

Step 5 - Add StoreBuilder namespaces to your Web.config for Razor views

Add the StoreBuilder namespace to the Web.config in your Views folder so that StoreBuilder HtmlHelper extension methods work properly in your Razor views.

<configuration>
  <system.web.webPages.razor>
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="StoreBuilder" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
</configuration>

Step 6 - Add a PageWrapper razor view

The StoreBuilder.Mvc nuget package contains an MVC StoreBuilderController which is used to integrate StoreBuilder functionality into a regular MVC project. While all StoreBuilder core features and plugins use Handlebars for templating, markup intended to be rendered as a page will be passed through this StoreBuilderController and wrapped with a surrounding Razor view in order to make site wide consistency easy for the MVC developer.

In your Views folder, add a new folder called 'StoreBuilder'. Then add a new Razor view in the StoreBuilder folder named 'PageWrapper.cshtml'.

As a minimum this template may appear as follows:

@model StoreBuilder.Content.Results.PageContentResult
@Html.Raw(Model.Body)
@section scripts{
    @Html.RenderScripts(Model.ThemeResourceArea)
}

Step 7 - Create a /themes folder for your StoreBuilder themes

StoreBuilder will be default look for a /themes folder in the root of your project to discover any StoreBuilder theme files. Each theme should be contained within a subfolder of the root /themes folder.

The default theme should be aptly named 'default' and contained within the /themes/default folder.

For more information see StoreBuilder ThemeEngine.

Step 8 - Secure the /storebuilder project path

If you installed the StoreBuilder.Admin nuget package, it will have added the StoreBuilder folder to your web project which contains an admin portal for StoreBuilder. All the API used by this admin portal will already be secured, however securing the admin portal files will add one more layer of protection to your website and prevent public review of your admin portal code or configuration.

<location path="storebuilder">
  <system.web>
    <authorization>
      <allow roles="StoreBuilder.Admin" />
      <deny users="*" />
    </authorization>
  </system.web>
</location>