Post

Set up EPiServer CMS and Commerce with AspNet Identity from scratch

Back to 2015, I wrote a blog post - Set up EPiServer CMS + Commerce in 11 steps based on Episerver version 9. After 4 years, the setup steps still largely remain the same if you want to use default aspnet membership. Thanks to Episerver product development team great work to keep the platform upgrade and maintain the backward compabilities.

In this blog post, I will walk you through from beginning on setup CMS Commerce first, then follow by setup identity on both Commerce manager and CMS. If you’re already familiar with CMS and Commerce setup, you can skip Set up CMS project with Commerce, Set up Commerce project (Commerce manager) and jump to Set up AspNet Identity in Commerce project, Set up ASpNet Identity in CMS project directly.

  • TOC

Prerequisites

  • Visual Studio 2017/2019
  • Windows 10 with localdb installed.
  • EPiServer CMS VSIX. (You can install within Visual Studio Extension Manager or download from here)

Getting Started

Set up CMS project with Commerce

  1. Use EPiServer VSIX template to set up an empty CMS project. _config.yml
  2. UPDATE all EPiServer packages to latest except Castle and Newtonsoft.Json.

    Warning: At the time of writing this blog post, the latest EPiServer.Commerce is 13.10.0, and it has dependecy on EPiServer.Commerce.Core which depends on Newtonsoft.Json (≥ 9.0.1 && < 12.0.0) The EPiServer.CMS.Core has dependency on Castle.Windsor (≥ 4.1.0 && < 5.0.0)

  3. Install EPiServer.Commerce package into CMS project.
  4. Run cmdlet update-epidatabase via nuget package console to update database with all latestes SQL scripts.
  5. Login to CMS administrative interface with default credntials, then clicks “execute all pending steps” link to run the migration

    username : admin

    password : store

    _config.yml

  6. Once complete the migration, go to verify both CMS and Commerce. _config.yml _config.yml _config.yml

Set up Commerce project (Commerce manager)

  1. Create an empty Mvc application with Visual Studio. _config.yml
  2. Install Episerver.CommerceManager package into Commerce project. _config.yml
  3. Run cmdlet update-epidatabase via package manager console.
  4. Show all files and include App_Data,App_GlobalResources,Apps, NotificationTemplates folders and Default,Global.asax,EPiServerDefault.aspx,EPiServerLog.config files. _config.yml
  5. Make sure “CommerceManagerLink” in CMS is pointing to commerce manager url.
1
<add key="CommerceManagerLink" value="http://localhost:{port}/" />

Set up AspNet Identity in Commerce Manager project

  1. Install EPiServer.CMS.UI.AspNetIdentity package into the Commerce project.
  2. Install EPiServer.ServiceLocation.StructureMap package into the Commerce project.
  3. Create an Owin startup named Startup.cs under root of Commerce project.
  4. Execute the SQL script will create default user admin@example.com with password store in AspNet Identity table
  5. Create Overrides folder under root and create the following web form page/control under Overrides folder. Commerce Manager is a legacy WebForm system, and coupled with old ASP.NET membership provider by default. What we’re doing here is to create custom version of login/logut page and later in the code-behind file we can overwrite with AspNet Identity implementation.
  1. Locate login.aspx and logout.aspx file under /Apps/Shell/Pages/ directory, MembershipAccountEdit.ascx file under /Apps/Shell/Customer/Modules, and update the Page directive with your custom one accordingly. _config.yml _config.yml

  2. Add a new Initialization Module file - IdentityInitialisation.cs under your Commerce Manager root folder.

    NOTES: This module is primarily used for adding Identity dependencies to IoC container, so in MemberShipAccountEdit user control code-behind, we can get instance of ApplicationUserManager and ApplicationSignInManager from ServiceLocation.

  3. Add the following <location> elements to your Commerce project web.config `xml

    `

    NOTES: This step is important, otherwise you’ll get infinite redirect loop when access to commerce manager logi.aspx page.

  4. Locate authentication section in web.config and change mode to None _config.yml
  5. Locate membership section in web.config and replace with the following
1
2
3
4
5
  <membership>
    <providers>
      <clear />
    </providers>
  </membership>
  1. Locate roleManager section in web.config and replace with the following
1
2
3
4
5
  <roleManager>
    <providers>
      <clear />
    </providers>
  </roleManager>

Set up AspNet Identity in CMS project

  1. Create an Owin startup named Startup.cs under root of CMS project.
  2. Locate authentication section in web.config and change mode to None
  3. Locate membership section in web.config and replace with the following
1
2
3
4
5
  <membership>
    <providers>
      <clear />
    </providers>
  </membership>
  1. Locate roleManager section in web.config and replace with the following
1
2
3
4
5
  <roleManager>
    <providers>
      <clear />
    </providers>
  </roleManager>

It’s the end, and that’s all you need to do for the setup. Enjoy your Episerver development with ASPNET Identity.

References

Happy Coding! 😇

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.

© Vincent. Some rights reserved.