asp.net core 2.2重定向身份loginpath

问题描述 投票:1回答:1

在我们当前的设置中,我们有一个已知的登录路径。但是现在我们正在使用核心2.2我无法解决当前的问题;这总是使用loginPath:/Identity/Account/Login,但我们想改变它。

在StackOverflow和其他人上阅读很多,我似乎无法解决它。所以现在我有一个全新的MVC应用程序试图弄清楚我做错了什么。

在我的创业公司,我有:

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.AddIdentity<IdentityUser, IdentityRole>()
        //                .AddDefaultUI()
        .AddEntityFrameworkStores<ApplicationDbContext>()
        .AddDefaultTokenProviders();

    services.ConfigureApplicationCookie(options =>
    {
        options.LoginPath = new PathString("/Account/Login2");
    });

   services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
        app.UseDatabaseErrorPage();
    }
    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.UseCookiePolicy();

    app.UseAuthentication();

    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
    });
}

}

我究竟做错了什么?更好的是;解决办法是什么 :)

asp.net-core-2.2
1个回答
1
投票

事实证明;

我需要脚手架一个标识项(如login),并在登录剃刀页面(login.cshtml)中添加:

@page "~/account/login2"

这也许你可以在启动时修复剃刀中的路由:

.AddRazorPagesOptions(options => {...});

尚未尝试过,但那是别的......

干杯

© www.soinside.com 2019 - 2024. All rights reserved.