Notes/Program.cs

40 lines
925 B
C#
Raw Normal View History

2023-01-25 13:48:50 +00:00
using BinaryDad.Notes;
2023-01-05 15:32:21 +00:00
using BinaryDad.Notes.Services;
using Microsoft.AspNetCore.Authentication.Cookies;
2023-01-05 15:32:21 +00:00
2022-11-29 15:14:15 +00:00
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
2023-01-25 13:48:50 +00:00
builder.Services.AddSignalR();
2023-01-05 15:32:21 +00:00
builder.Services.AddSingleton<INoteService, FileNoteService>();
2022-11-29 15:14:15 +00:00
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(o =>
{
o.LoginPath = "/login";
2023-06-21 14:49:13 +00:00
o.Cookie.Name = "NotesUser";
o.Cookie.MaxAge = TimeSpan.FromDays(3);
});
2022-11-29 15:14:15 +00:00
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
2023-01-09 21:56:30 +00:00
app.UseHttpsRedirection();
2022-11-29 15:14:15 +00:00
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
2022-11-29 15:14:15 +00:00
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Note}/{action=Index}/{id?}");
2022-11-29 15:14:15 +00:00
2023-01-25 13:48:50 +00:00
app.MapHub<NoteHub>("/noteHub");
2022-11-29 15:14:15 +00:00
app.Run();