为 IdentityServer4 安装快速入门 UI

Installing Quickstart UI for IdentityServer4

我创建了一个空的 asp.net 核心 Web 应用程序 (dotnet new web -n <projectname>),然后 to the github for IdentityServer4.Quickstart.UI 并按照说明添加了快速入门 UI。我首先执行 powershell cmd iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/IdentityServer/IdentityServer4.Quickstart.UI/main/getmain.ps1')) 下载文件和 运行 应用程序,但它一直告诉我 Index not found 但文件在 Views 文件夹中。因此,我然后删除了它从项目下载的所有文件,并通过 运行ning 命令 dotnet new -i identityserver4.templates 然后 dotnet new is4ui --force 使用其模板安装它,这再次将这些文件下载到我的项目中。但是,它一直告诉我同样的信息。

我注意到在 Quickstart 文件夹下,包含一个名为 Home 的文件夹,其中包含 HomeController.cs,命名空间为 IdentityServerHost.Quickstart.UI。 .. 我是否需要更改该名称空间以匹配我的解决方案,即 ids.Quickstart.Home?

实际上在 Views 文件夹中有 Index.cshtml 文件,是什么导致显示该错误?**

这是我的 startup.cs 文件:

namespace ids
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentityServer()
                .AddInMemoryClients(Config.Clients)
                .AddInMemoryIdentityResources(Config.IdentityResources)
                .AddInMemoryApiResources(Config.ApiResources)
                .AddInMemoryApiScopes(Config.ApiScopes)
                .AddTestUsers(Config.Users)
                .AddDeveloperSigningCredential();

            services.AddControllersWithViews();
        }

        // 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.UseRouting();
            app.UseStaticFiles();
            app.UseIdentityServer();
            app.UseAuthorization();

            //  app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

        }
    }
}

这里是Index.cshtml

尝试在 Configure() 方法中将 app.UseEndpoints( endpoints => ...) 行更改为以下内容:

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
});

然后,确保你有 HomeController。在您的项目中创建一个名为 Controllers 的文件夹。路径应为 ~/Controllers/{ControllerName}.cs,而您的视图应为 ~/Views/Home/{ViewName}.cshtml。在这种情况下,您的 {ViewName}.cshtml 将是 Index.cshtml 并且您的控制器名称将是 HomeController.cs.

public class HomeController : Controller
{
    [HttpGet]
    // Default return when user performs GET HTTP request
    public IActionResult Index()
    {
        return View();
    }
}
 

右键单击 Index.cshtml,选择 属性 选项。检查中的设置 属性 windows。 Index.cshtml 的构建操作必须是 Content.