Project details:
I created an own login view. Actually if I call a view, for which I have to be authorized (by authorize attribute), it will automatically redirected to the login view. But at the moment it's "/Identity/Account/Login". But I want, that my own login view is shown. How can I do that?
I already tried this within startup.cs:
services.AddDefaultIdentity<ApplicationUser>(config => { config.SignIn.RequireConfirmedEmail = true; })
.AddDefaultUI(UIFramework.Bootstrap4).AddEntityFrameworkStores<ApplicationDbContext>();
services.Configure<IdentityOptions>(options => { options.User.RequireUniqueEmail = true; });
services.ConfigureApplicationCookie(options =>
{
options.Cookie.Name = "auth_cookie";
options.AccessDeniedPath = "/Account/Login";
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/LogOff";
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
options.SlidingExpiration = true;
});
You could try to configure CookieAuthenticationOptions
to achieve your requirement.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>()
.AddDefaultUI(UIFramework.Bootstrap4)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.PostConfigure<CookieAuthenticationOptions>(IdentityConstants.ApplicationScheme,
opt =>
{
//configure your other properties
opt.LoginPath = "/Login";
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With