106 lines
No EOL
3.3 KiB
C#
106 lines
No EOL
3.3 KiB
C#
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using RdtClient.Data.DataContext;
|
|
using RdtClient.Data.Models.Internal;
|
|
|
|
namespace RdtClient.Web
|
|
{
|
|
public class Startup
|
|
{
|
|
private IConfiguration Configuration { get; }
|
|
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
var appSettings = new AppSettings();
|
|
Configuration.Bind(appSettings);
|
|
|
|
services.AddSingleton(appSettings);
|
|
|
|
services.AddDbContext<DataContext>(options => options.UseSqlite(appSettings.ConnectionStrings.Client));
|
|
|
|
services.AddControllers();
|
|
|
|
services.AddSpaStaticFiles(configuration =>
|
|
{
|
|
configuration.RootPath = "wwwroot";
|
|
});
|
|
|
|
services.AddHttpContextAccessor();
|
|
|
|
services.AddCors(options =>
|
|
{
|
|
options.AddPolicy("Dev",
|
|
builder =>
|
|
{
|
|
builder.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowAnyOrigin();
|
|
});
|
|
});
|
|
|
|
services.AddHttpsRedirection(options => { options.HttpsPort = 443; });
|
|
|
|
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
|
.AddCookie(options => { options.SlidingExpiration = true; });
|
|
|
|
services.AddAuthorization();
|
|
|
|
services.AddIdentity<IdentityUser, IdentityRole>(options =>
|
|
{
|
|
options.User.RequireUniqueEmail = true;
|
|
options.Password.RequiredLength = 10;
|
|
options.Password.RequireUppercase = false;
|
|
options.Password.RequireLowercase = false;
|
|
options.Password.RequireNonAlphanumeric = false;
|
|
options.Password.RequiredUniqueChars = 5;
|
|
})
|
|
.AddEntityFrameworkStores<DataContext>()
|
|
.AddDefaultTokenProviders();
|
|
|
|
Data.DiConfig.Config(services);
|
|
Service.DiConfig.Config(services);
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
app.UseCors("Dev");
|
|
}
|
|
else
|
|
{
|
|
app.UseHttpsRedirection();
|
|
}
|
|
|
|
app.UseDefaultFiles();
|
|
|
|
app.UseSpaStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
});
|
|
|
|
app.UseSpa(spa =>
|
|
{
|
|
spa.Options.SourcePath = "wwwroot";
|
|
});
|
|
}
|
|
}
|
|
} |