Home > Software design >  Error while scaffolding identify in dotnet
Error while scaffolding identify in dotnet

Time:10-07

I followed the video by brughen Patel for the Identity scaffolding walk-around, everything went well, but when i ran the application,it showed me this.

"This localhost page can't be found". "No webpage was found for the web address: https://localhost:7210"

Can someone please help out, I'm stuck. How do I solve it?

using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using MyBook.DataAccess;
using MyBook.DataAccess.Repository;
using MyBook.DataAccess.Repository.IRepository;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<ApplicationDbcontext>(options => options.UseSqlServer(
    builder.Configuration.GetConnectionString("DefaultConnection")
    ));
builder.Services.AddDefaultIdentity<IdentityUser>()
    .AddEntityFrameworkStores<ApplicationDbcontext>();

builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

// The Codes below are called middlewares.They are part of the request pipeline.
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();
app.UseAuthentication(); 
// app.UseAuthentication(); // this is an authentication middleware. It comes before the authorization middleware.
app.UseAuthorization();

app.MapRazorPages();
app.MapControllerRoute(
    name: "default",
    pattern: "{area=Customer}/{controller=Home}/{action=Index}/{id?}");  


//app.MapRazorPages();
app.Run();

CodePudding user response:

Add Area at Controller level like below:

[Area("Customer")]
public class HomeController : Controller

After that register your area route like below:

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Customer_default",
        "Customer/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional },
        new { controller = "Home" },
        new[] { "MyApp.Areas.Customer.Controllers" }
    );
}
  • Related