.NET Core升级中无.cshtml的Razor Pages找不到Login视图
.NET Core 2.2升级后IdentityServer4找不到Login视图的缺失配置排查
安装IdentityServer4.UI NuGet包
新版本IdentityServer4不再内置登录等UI视图,需手动安装IdentityServer4.UI包,在服务注册时添加默认UI支持:builder.Services.AddIdentityServer() .AddDefaultUI() .AddInMemoryClients(Config.Clients) .AddInMemoryIdentityResources(Config.IdentityResources) .AddInMemoryApiScopes(Config.ApiScopes) .AddTestUsers(TestUsers.Users);启用Razor Pages服务与中间件
若使用Razor Pages实现身份页面,需在Program.cs中正确配置:// 注册Razor Pages服务 builder.Services.AddRazorPages(); // 配置中间件(注意顺序:UseRouting之后,UseIdentityServer之前) app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseIdentityServer(); // 映射Razor Pages路由 app.MapRazorPages();确认视图文件路径与自定义路由
Razor Pages规范下,登录页面默认路径为/Pages/Account/Login.cshtml(而非传统Views目录)。若使用自定义路径,需在IdentityServer配置中明确指定:builder.Services.AddIdentityServer(options => { options.UserInteraction.LoginUrl = "/YourCustomPath/Login"; options.UserInteraction.LogoutUrl = "/YourCustomPath/Logout"; })检查文件生成配置
确保Razor Pages的.cshtml文件生成操作设为Content,复制到输出目录设为如果较新则复制——即使之前修改过,也需确认配置未被项目文件覆盖。验证MVC视图引擎配置(若混用)
若项目同时依赖MVC视图,需确保服务注册时启用视图支持:builder.Services.AddControllersWithViews();
内容的提问来源于stack exchange,提问作者Rutger
相关产品推荐
相关产品推荐

