Skip to content

Instantly share code, notes, and snippets.

@javafun
Created November 17, 2019 11:04
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/dccbbf0c22bd5dbb0902da4e622a09a6 to your computer and use it in GitHub Desktop.
Save javafun/dccbbf0c22bd5dbb0902da4e622a09a6 to your computer and use it in GitHub Desktop.
CMS Startup Class
using System;
using System.Threading.Tasks;
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.CMS.Startup))]
namespace Web.CMS
{
public class Startup
{
private readonly IConnectionStringHandler _connectionStringHandler;
string loginPath = "/util/login.aspx";
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("/Login"),
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),
//OnResponseSignOut = context => context.Response.Redirect(UrlResolver.Current.GetUrl(ContentReference.StartPage))
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment