gpt4 book ai didi

c# - 切换到 .net core 3 端点路由后,身份 UI 不再工作

转载 作者:行者123 更新时间:2023-12-02 15:02:27 25 4
gpt4 key购买 nike

在很难让我的区域通过端点路由显示后,我设法在这个 self 回答的线程中修复它(尽管不是以非常令人满意的方式):Issue after migrating from 2.2 to 3.0, default works but can't access area, is there anyway to debug the endpoint resolution?

但是身份用户界面根本不显示给我,我在挑战时被重定向到正确的网址,但页面是空白的。我添加了身份 UI block 包,并且从 mvc 路由更改为端点路由,我没有更改任何会破坏它的内容。

我似乎也没有做太多不同于默认项目的事情,即使我像在黑客中那样添加路线,身份也可以在那里工作。

由于问题经常隐藏在线路周围而不是线路上,因此我会发布整个启动文件。

常规(默认) Controller 可以工作。管理区域有效(其中一个页面没有身份验证,我可以访问它)任何其他管理区域页面将我重定向到/Identity/Account/Login?ReturnUrl=%2Fback (预期行为),但该页面以及我测试的任何其他/Identity 页面在调试中运行并附加调试器时都是空白,没有错误.

非常感谢任何帮助,完整启动如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using FranceMontgolfieres.Models;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;

namespace FranceMontgolfieres
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IConfiguration>(Configuration);

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<FMContext>(options => options
.UseLazyLoadingProxies(true)
.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

services
.AddDefaultIdentity<IdentityUser>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<FMContext>();

services
.AddMemoryCache();

services.AddDistributedSqlServerCache(options =>
{
options.ConnectionString = Configuration.GetConnectionString("SessionConnection");
options.SchemaName = "dbo";
options.TableName = "SessionCache";
});

services.AddHttpContextAccessor();

services
.AddSession(options => options.IdleTimeout = TimeSpan.FromMinutes(30));

services.AddControllersWithViews();
services.AddRazorPages();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment 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.UseRouting();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseAuthorization();
app.UseSession();

app.UseEndpoints(endpoints =>
{
endpoints.MapAreaControllerRoute("Back", "Back", "back/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute("default","{controller=Home}/{action=Index}/{id?}");
});
}

private async Task CreateRoles(IServiceProvider serviceProvider)
{
//initializing custom roles
var RoleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();
string[] roleNames = { "Admin", "Manager", "Member" };
IdentityResult roleResult;

foreach (var roleName in roleNames)
{
roleResult = await RoleManager.CreateAsync(new IdentityRole(roleName));
}
}
}
}

最佳答案

身份 UI 是使用 Razor Pages 实现的。对于端点路由来映射这些,请在 UseEndpoints 回调中添加对 MapRazorPages 的调用:

app.UseEndpoints(endpoints =>
{
// ...
endpoints.MapRazorPages();
});

关于c# - 切换到 .net core 3 端点路由后,身份 UI 不再工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58260002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com