【发布时间】: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