-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
91 lines (75 loc) · 2.8 KB
/
Program.cs
File metadata and controls
91 lines (75 loc) · 2.8 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using Elmah.Io.AspNetCore;
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using PersonalizedCardGame.Hubs;
using PersonalizedCardGame.Middleware;
using PersonalizedCardGame.Models;
using SignalRChat.Hubs;
using System.Security.Claims;
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
// Add services to the container.
builder.Services.AddControllersWithViews().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
builder.Services.AddDbContext<DBCardGameContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString(builder.Environment.IsDevelopment() ? "DbCoreConnectionString" : "DbCoreConnectionString_Deploy") ?? throw new InvalidOperationException("Connection string 'DbCoreConnectionString' not found.")));
builder.Services.AddIdentity<AppUser, IdentityRole>().AddEntityFrameworkStores<DBCardGameContext>().AddDefaultTokenProviders()
.AddRoles<IdentityRole>();
services.Configure<IdentityOptions>(opt =>
{
opt.Password.RequiredLength = 6;
opt.Password.RequireNonAlphanumeric = false;
opt.Password.RequireDigit = true;
opt.Password.RequireLowercase = true;
opt.Password.RequireUppercase = false;
opt.User.RequireUniqueEmail = true;
opt.ClaimsIdentity.UserIdClaimType = ClaimTypes.NameIdentifier;
opt.Lockout.MaxFailedAccessAttempts = 3;
opt.Lockout.DefaultLockoutTimeSpan = System.TimeSpan.FromMinutes(10);
});
services.AddCors(options => options.AddPolicy("CorsPolicy",
builder =>
{
builder.AllowAnyHeader()
.AllowAnyMethod()
.SetIsOriginAllowed((host) => true)
.AllowCredentials();
}));
services.AddDistributedMemoryCache();
services.Configure<ElmahIoOptions>(builder.Configuration.GetSection("ElmahIo"));
services.AddElmahIo();
builder.Services.AddHttpContextAccessor();
builder.Services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Auth/SignIn";
});
builder.Services.AddSession(options =>
{
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
builder.Services.AddSignalR();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseStaticFiles();
app.MapFallbackToFile("index.html");
}
if (app.Environment.IsDevelopment())
{
app.UseCors("CorsPolicy");
}
app.UseRouting();
app.UseAuthentication();
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
app.UseMiddleware<JwtMiddleware>();
app.UseElmahIo();
app.MapHub<GameClass>("/GameClass"/*,
options.Transports = HttpTransportType.WebSockets;
}*/);
app.MapHub<MyHub>("/MyHub");
app.Run();