asp.net core 身份和身份服务器

LDJ*_*LDJ 3 asp.net asp.net-core identityserver4

我正在遵循有关将 asp.net core 身份与 IdentityServer 集成的演练,但遇到了一些障碍。

如果我按照指南并使用,我正在更新ConfigureServices方法

services.AddIdentity<IdentityUser, IdentityRole>()
        .AddEntityFrameworkStores<ApplicationDbContext>()
        .AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)

我无法再访问任何与帐户相关的功能。寄存器链接的路由更改为

~/Identity/Account/Register
Run Code Online (Sandbox Code Playgroud)

~/?area=Identity&page=%2FAccount%2FRegister
Run Code Online (Sandbox Code Playgroud)

这会破坏所有与帐户相关的功能

如果我把它留在

services.AddDefaultIdentity<IdentityUser>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)

然后路由仍然有效,我可以通过登录页面输入我的凭据并且登录成功,但是

SignInManager.IsSignedIn(User)
Run Code Online (Sandbox Code Playgroud)

返回 false,所以我猜这里有些东西从根本上被破坏了。

我已将identityserver添加到我的ConfigureServices中:

    services.AddIdentityServer()
                    .AddDeveloperSigningCredential()
                    .AddInMemoryPersistedGrants()
.AddInMemoryIdentityResources(Config.IdentityResources.GetIdentityResources())
                    .AddInMemoryApiResources(Config.APIResources.GetApiResources())
                    .AddInMemoryClients(Config.Clients.GetClients())
                    .AddAspNetIdentity<IdentityUser>();
Run Code Online (Sandbox Code Playgroud)

有什么需要改变的想法 - 我猜是最新版本的 asp.net core 中的某些东西导致了这个问题?

小智 5

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

app.UseEndpoints(endpoints =>
{
// ...
endpoints.MapRazorPages();
});
Run Code Online (Sandbox Code Playgroud)