forked from argonautsec/NoteGoat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (50 loc) · 1.63 KB
/
Program.cs
File metadata and controls
60 lines (50 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using NoteGoat.Data;
using Microsoft.AspNetCore.Identity;
using NoteGoat.Models;
using NoteGoat.Areas.Identity.Seed;
using NoteGoat.Logging;
using NoteGoat;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddMvc();
builder.Services.AddDbContext<NoteGoatContext>(
opts =>
opts.UseSqlite(
builder.Configuration.GetConnectionString(
"NoteGoatContext"
)
?? throw new InvalidOperationException(
"Connection string 'NoteContext' not found."
)
)
);
builder.Services
.AddDefaultIdentity<User>(
options => options.SignIn.RequireConfirmedAccount = true
)
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<NoteGoatContext>();
builder.Services.ConfigureApplicationCookie(o =>
{
o.SlidingExpiration = true;
o.AccessDeniedPath = "/Identity/Account/AccessDenied";
});
builder.Logging.AddFile();
var app = builder.Build();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapDefaultControllerRoute();
app.MapRazorPages();
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var roleManager = services.GetRequiredService<
RoleManager<IdentityRole>
>();
await IdentityRoleSeeder.SeedRoles(roleManager);
}
app.Run();