在ASP.net Core 3.0中更改身份登录URL [英] Change identity login URL in ASP.net core 3.0

查看:54
本文介绍了在ASP.net Core 3.0中更改身份登录URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从以下位置更改默认登录URL:

I'm trying to change the default login URL from:

 /Identity/Account/Login

/Login

我查找了类似的问题,他们想出了一个与此类似的解决方案:

I've looked up similar questions and they came up with a solution similar to this:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<CompanyLoginContext>(options =>
        options.UseNpgsql(
            Configuration.GetConnectionString("DefaultConnection")));

    services.AddIdentity<CompanyLoginUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
       .AddEntityFrameworkStores<CompanyLoginContext>()
       .AddDefaultTokenProviders();

    services.ConfigureApplicationCookie(options =>
    {
        options.Cookie.HttpOnly = true;
        options.ExpireTimeSpan = TimeSpan.FromMinutes(10);

        options.LoginPath = new PathString("/Login");
        options.AccessDeniedPath = new PathString("/Logout");
        options.AccessDeniedPath = new PathString("/AccessDenied");

        options.SlidingExpiration = true;
    }); 
}

但是这不起作用.

推荐答案

请确保已对身份进行验证,您可以参考

Be sure that you have scalffolded Identity,you could refer to here.

然后您需要修改 Identity/Account/Login.cshtml ,如下所示:

Then you need to modify Identity/Account/Login.cshtml like below:

@page "/Login"

这篇关于在ASP.net Core 3.0中更改身份登录URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆