Search code examples
c#configurationasp.net-identityasp.net-core-2.0aspnetboilerplate

Aspnetboilerplate: Configure login path for redirect on core mvc template


Sorry if this is straightforward, but I'm having a real block with this one.

I'm trying to move all the standard views and controllers from aspnetboilerplate's Module Zero (Core + MVC + jQuery) into a new area (Admin) and want to make sure the redirect for login on unauthorized view goes to /Admin/Login as opposed to /Account/Login, which is the default.

Any help really appreciated.

Dale

Update

Here is the ConfigureServices method:

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    //MVC
    services.AddMvc(options =>
    {
        options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
    });

    IdentityRegistrar.Register(services);
    AuthConfigurer.Configure(services, _appConfiguration);

    services.ConfigureApplicationCookie(options => options.LoginPath = "/Admin/Login");

    services.AddScoped<IWebResourceManager, WebResourceManager>();

    //Configure Abp and Dependency Injection
    return services.AddAbp<CrowdsiteWebMvcModule>(options =>
    {
        //Configure Log4Net logging
        options.IocManager.IocContainer.AddFacility<LoggingFacility>(
            f => f.UseAbpLog4Net().WithConfig("log4net.config")
        );
    });
}

Solution

  • You can configure that in Startup.cs:

    IdentityRegistrar.Register(services);
    AuthConfigurer.Configure(services, _appConfiguration);
    
    // Add this line:
    services.ConfigureApplicationCookie(options => options.LoginPath = "/Admin/Login");
    

    Related docs: https://learn.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x