【问题标题】:Installing Quickstart UI for IdentityServer4为 IdentityServer4 安装 Quickstart UI
【发布时间】:2021-08-31 10:02:31
【问题描述】:

我创建了一个空的 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 文件夹内。因此,我删除了它从项目中下载的所有文件,并使用其模板通过运行 cmds 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

【问题讨论】:

  • 确保您的视图存储在像~/Views/{ControllerName}/{ViewName}这样的文件夹结构中
  • 就像有一个名为HomeController的控制器?
  • 对。一个视图需要一个相应的控制器来处理它的请求——如果我正确理解了整个事情的话。

标签: c# asp.net-core asp.net-core-webapi identityserver4


【解决方案1】:

尝试在 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 文件是您所说的与名为 Home 的控制器一起使用的文件,但它仍然会在程序启动后立即显示
  • 这可能也是一篇有用的文章:docs.microsoft.com/en-us/aspnet/core/mvc/controllers/…
  • 遵循本教程也是我学习如何设置我的第一个 ASP.NET Core 项目的方法:docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/…
  • @NoviceCoder,还要仔细检查您的foldersmethodscalls 等的拼写。否则它可能会试图寻找一个实际上并不存在的地方。我遇到过几次。
  • 感谢您的文章和帮助!我将对此进行调查并仔细检查每个项目的拼写,再次感谢!
【解决方案2】:

右击Index.cshtml,选择属性选项。检查中的设置 属性窗口。 Index.cshtml 的构建动作必须是Content

【讨论】:

  • 我刚刚检查了它是否如您的屏幕截图所示,它仍然与您的屏幕截图完全相同:(
  • 请看看我更新的帖子,这样你就可以看到我到底想要做什么......也许你能看到这个问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多