Code: Select all
using ObjectCrudApp.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using ObjectCrudApp.Areas.Identity.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container
builder.Services.AddDbContext(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true).AddEntityFrameworkStores();
// Configure Identity services
builder.Services.AddIdentity(options =>
options.SignIn.RequireConfirmedAccount = false) // Customize as per your needs
.AddEntityFrameworkStores() // Use the same DbContext for both App and Identity
.AddDefaultTokenProviders();
// Configure Application Cookie for Access Denied
builder.Services.ConfigureApplicationCookie(options =>
{
options.AccessDeniedPath = "/Identity/Account/AccessDenied"; // Path to redirect when access is denied
});
// Add MVC services to the container
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts(); // HTTP Strict Transport Security
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication(); // Make sure authentication comes before authorization
app.UseAuthorization();
// Map the controller routes
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
< /code>
Ich habe den Befehl ausgeführt: < /p>
dotnet aspnet-codegenerator identity --useDefaultUI --force
Code: Select all
Login.cshtml
Here is the screenshot of my project directory:
Ich versuche, die Identitäts -UI mit Anmeldung und Registrierung für meine ASP.NET -Kernanwendung zu registrieren. Ich möchte, dass mein Befehl login.cshtml und registrieren.cshtml Nachdem ich den Befehl scastolding ausgeführt habe.