-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
39 lines (28 loc) · 1.36 KB
/
Copy pathProgram.cs
File metadata and controls
39 lines (28 loc) · 1.36 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
using Microsoft.AspNetCore.Authentication.Cookies;
var builder = WebApplication.CreateBuilder(args);
// Configure cookie-based authentication.
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
{
// Specify the path to the login page when authentication is required.
options.LoginPath = new PathString("/Auth/SignUp");
// Specify the path to handle cases when a user is denied access due to insufficient permissions.
//options.AccessDeniedPath = new PathString("/Auth/SignUp");
// Specify the path to redirect after logout.
//options.LogoutPath = new PathString("/Auth/SignUp");
});
// Register services required by controllers and views.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Middleware to serve static files like CSS, JS, and images from the 'wwwroot' folder.
app.UseStaticFiles();
// Enable authentication middleware to protect routes that require user login.
app.UseAuthentication();
// Enable authorization middleware to enforce access control based on user roles or claims.
app.UseAuthorization();
// Define the default route pattern for MVC.
// This sets the "Home" controller's "Index" action as the default page (when navigating to "/").
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"
);
app.Run();