< back

Configure StoreBuilder with new ASP.NET MVC Project

Step 1 - Create a new MVC Project

Step 2 - Add StoreBuilder Nuget Packages

StoreBuilder hosts a private nuget server for our components. If this is your first time using StoreBuilder Nuget, please see Configuring Visual Studio to access the StoreBuilder Nuget Server

Add StoreBuilder Nuget Packages:

  • StoreBuilder
  • StoreBuilder.HandlebarsCompiler
  • StoreBuilder.Log4net
  • StoreBuilder.Mvc
  • StoreBuilder.AspNetIdentity
  • StoreBuilder.WebsiteManager

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.

Part A - Add configSection declaration:

<section name="storebuilder" type="StoreBuilder.Config, StoreBuilder" />

Part B - Add <storebuilder> configuration element.

<storebuilder>
  <database connectionStringName="Storefront" />
  <logProvider type="StoreBuilder.Log4Net.LogProvider, StoreBuilder.Log4Net" />
  <securityProvider type="StoreBuilder.AspNetIdentity.IdentitySecurityProvider, StoreBuilder.AspNetIdentity" />
  <license accountKey="XXXX-XXXX-XXXX-XXXX" licenseKey="XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX" />
</storebuilder>

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 temlpatetemplate by removing

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

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 styles{
@Html.RenderStyles(Model.ThemeResourceArea)
}
@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. While not absolutely required, StoreBuilder recommends a functional organization structure for themes with subfolders for functional areas of the website:

  • /everywhere contains JS/CSS that should be included everywhere on your website (all pages).
  • /listing contains JS/CSS/HBS files that will be loaded/used on product listing type pages in addition to anything that was included 'everywhere'. Listing pages include Category pages, Brand pages, Tag pages and Search results.
  • /product contains JS/CSS/HBS files that will be loaded/used on product pages in addition to anything that was included 'everywhere'.
  • /cart contains JS/CSS/HBS files that will be loaded/used on the cart page in addition to anything that was included 'everywhere'.
  • /checkout contains JS/CSS/HBS files that will be loaded/used on the checkout page(s) in addition to anything that was included 'everywhere'.
  • '/account` contains JS/CSS/HBS files that will be loaded/used on the customer account page(s) in addition to anything that was included 'everywhere'.
  • /plugins contains JS/CSS/HBS files that have been provided by any installed plugins. After a plugin has been installed, you have the option to customize the plugin JS/CSS/HBS files to match your branding or unique requirements.
  • /emails contains HBS templates for emails that StoreBuilder may send.

For more information see StoreBuilder ThemeEngine.

Optional, Use a pre-built StoreBuilder theme to get started quickly

If you want to get started quickly you can add one of our pre-built themes to your project using Nuget.

  • StoreBuilder.Bootstrap3Theme

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>