无法使Identity Server启动默认主页

时间:2018-11-15 10:23:28

标签: asp.net-core-2.0 identityserver4

我正在从APS.Net Core v1上编写的代码中学习设置身份服务器,并且正在使用v2,包括Identity Server的快速入门代码。 我具有默认索引页面,该页面设置了快速入门代码随附的家庭控制器。 我发现这段代码会启动控制台,但不会启动网页。

   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)
        {
            var url =
                @"C:\Users\xxxx\Documents\Visual Studio 2017\Projects\SIR\SIR.OAUTH\SIR_SSL_Certificate.pfx";
            services.AddIdentityServer()
                .AddSigningCredential(new X509Certificate2(url, "xxxxxxxx"))
                .AddTestUsers(InMemoryConfiguration.Users().ToList())
                .AddInMemoryClients(InMemoryConfiguration.Clients())
                .AddInMemoryApiResources(InMemoryConfiguration.ApiResources());
            services.AddMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();
            app.UseDeveloperExceptionPage();
            app.UseIdentityServer();
            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();
        }
    }

执行行app.UseMvcWithDefaultRoute();,但未启动“索引”页面。我在做什么错了?

编辑:这是注释中要求的控制台日志; enter image description here

1 个答案:

答案 0 :(得分:0)

我真的希望这行得通,因为我在今年早些时候遇到过同一问题。 我必须将services.addMVC/configure.addMVC放在服务的顶部,并放在方法调用的底部。这是一个示例:

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //mvc  //-------------------------->HERE!!!!!!!!!!
            services.AddMvc();

            //add indentity server
            services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddTestUsers(Config.GetUsers())//<---gets from static method in Config class
                .AddInMemoryIdentityResources(Config.GetIdentityResources())//<-method in Config class
                .AddInMemoryApiResources(Config.GetApiResources()) //PASS In api res list frm cnfg
                .AddInMemoryClients(Config.GetClients());//--Config getClients()





        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory lf)
        {
            //loggerfactory
            lf.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //call iden4
            app.UseIdentityServer();
            app.UseAuthentication();// just added 1-22 18
            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();
            app.UseMvc();  //---------------------------------------->HERE!!!
        }
    }