Search code examples
c#asp.netasp.net-coreroutesasp.net-identity

Change default identity Login route to something custom asp.net core


I saw a lot of other threads on this but no one ever said if it is possible to just rename the endpoint route of the Identity/Account/Login to something like /Home. Is it possible to do this without removing the AddDefaultIdentity from the Startup class?


Solution

  • Add Role services to Identity

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection")));
        services.AddDefaultIdentity<IdentityUser>()
            .AddRoles<IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>();
    
        services.AddControllersWithViews();
        services.AddRazorPages();
    }

    [Authorize(Roles = "Administrator")]
    public class AdministrationController : Controller
    {
    }