-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
64 lines (45 loc) · 1.69 KB
/
Program.cs
File metadata and controls
64 lines (45 loc) · 1.69 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
61
62
63
64
using FluentValidation;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using NetworkInfrastructure.Web.Data.Context;
using NetworkInfrastructure.Web.Data.Services;
using NetworkInfrastructure.Web.Models;
using NetworkInfrastructure.Web.Models.Profile;
using NetworkInfrastructure.Web.Models.Validate;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<NetworkContext>(x =>
{
x.UseSqlServer(builder.Configuration.GetConnectionString("NetConnection"));
});
builder.Services.AddAutoMapper(typeof(Profiler));
builder.Services.AddScoped<INetworkService, NetworkService>();
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IValidator<UserDto>, UserDtoValidation>();
builder.Services.AddScoped<IValidator<NetworkAssetDto>, NetworkAssetDtoValidation>();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(x =>
{
x.ExpireTimeSpan = TimeSpan.FromMinutes(20);
x.SlidingExpiration = true;
x.LoginPath = new PathString("/Network/Login/");
x.AccessDeniedPath = new PathString("/Network/Forbidden/");
x.Cookie.Name = "my_delicious_little_cookies";
});
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseCookiePolicy(new CookiePolicyOptions()
{
MinimumSameSitePolicy = SameSiteMode.Strict
});
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Network}/{action=Login}/{id?}");
app.Run();