Skip to content

Instantly share code, notes, and snippets.

@javafun
Last active November 17, 2019 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javafun/a921d94163e327e54154b37de6130b33 to your computer and use it in GitHub Desktop.
Save javafun/a921d94163e327e54154b37de6130b33 to your computer and use it in GitHub Desktop.
Commerce Manager Startup Class
using System;
using EPiServer.Cms.UI.AspNetIdentity;
using EPiServer.ServiceLocation;
using Mediachase.Data.Provider;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;
[assembly: OwinStartup(typeof(Web.Commerce.Startup))]
namespace Web.Commerce
{
public class Startup
{
private readonly IConnectionStringHandler _connectionStringHandler;
public Startup() : this(ServiceLocator.Current.GetInstance<IConnectionStringHandler>())
{
// Parameterless constructor required by OWIN.
}
public Startup(IConnectionStringHandler connectionStringHandler)
{
_connectionStringHandler = connectionStringHandler;
}
public void Configuration(IAppBuilder app)
{
app.AddCmsAspNetIdentity<ApplicationUser>(new ApplicationOptions
{
ConnectionStringName = _connectionStringHandler.Commerce.Name
});
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider.
// Configure the sign in cookie.
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Apps/Shell/Pages/Login.aspx"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager<ApplicationUser>, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => manager.GenerateUserIdentityAsync(user)),
OnApplyRedirect = (context => context.Response.Redirect(context.RedirectUri))
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment