Custom LoginPath no effect in ASP.NET MVC

In my ASP.NET MVC project, the default login path is /Account/Login. I want to configure It to be /User/Login when [Authorize] tag is used on the controller.

The following is the relevant code in Program.cs, it seems the setting in ConfigureApplicationCookie has no effect. It still redirects to /Account/Login.

using Auth0.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDbContextFactory<ApplicationDbContext>(options => options.UseSqlite(devConnString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();

builder.Services.ConfigureApplicationCookie(options =>
{
    options.LoginPath = new PathString("/User/Login");
    options.LogoutPath = new PathString("/User/Logout");
});

builder.Services.AddAuth0WebAppAuthentication(options =>
{
    options.Domain = builder.Configuration["Auth0:Domain"];
    options.ClientId = builder.Configuration["Auth0:ClientId"];
});

builder.Services.AddRazorPages();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseMigrationsEndPoint();
}
else
{
    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();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();
app.UseResponseCaching();
app.UseAuthentication();
app.UseAuthorization();

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

app.Run();
2 Likes

This is super annoying for me, is there an answer for this?

Please see this c# - Custom LoginPath no effect in ASP.NET MVC with Auth0 - Stack Overflow

After a long while finally some one managed to help provide a solution.

2 Likes

OK, many thanks, works now

1 Like

Thanks for sharing that with the rest of community!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.