71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Identity.DefaultUI.WebSite
|
|
{
|
|
public class StartupBase<TUser,TContext>
|
|
where TUser : class
|
|
where TContext : DbContext
|
|
{
|
|
public StartupBase(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public virtual void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.Configure<CookiePolicyOptions>(options =>
|
|
{
|
|
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
|
options.CheckConsentNeeded = context => true;
|
|
});
|
|
|
|
services.AddDbContext<TContext>(options =>
|
|
options.UseSqlServer(
|
|
Configuration.GetConnectionString("DefaultConnection"),
|
|
sqlOptions => sqlOptions.MigrationsAssembly("Identity.DefaultUI.WebSite")
|
|
));
|
|
|
|
services.AddDefaultIdentity<TUser>()
|
|
.AddRoles<IdentityRole>()
|
|
.AddEntityFrameworkStores<TContext>();
|
|
|
|
services.AddMvc();
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
app.UseDatabaseErrorPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Error");
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseStaticFiles();
|
|
app.UseCookiePolicy();
|
|
|
|
app.UseAuthentication();
|
|
|
|
app.UseMvc();
|
|
}
|
|
}
|
|
}
|