asp.net core mvc 显示空页

Jos*_*set 5 asp.net-core-mvc

拜托,我需要帮助解决有关 asp.net 核心 mvc 应用程序的烦人问题。

该应用程序仅显示空白主页 - 根本没有内容,包括 html 标记。即使直接在浏览器上输入 url 也不会调用控制器,也不会显示错误。

我重新创建了几次新应用程序,结果相同。此外,我在 Startup 类的 Configure 方法中添加了以下语句,但无济于事。

app.UseDefaultFiles();
app.UseStaticFiles();
app.UseIdentity();
Run Code Online (Sandbox Code Playgroud)

任何解开这个谜团的指南都将受到高度赞赏。

谢谢。

 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        //add NLog to ASP.NET Core
        //loggerFactory.AddNLog();

        ////add NLog.Web
        //app.AddNLogWeb();

        //needed for non-NETSTANDARD platforms: configure nlog.config in your project root
        //env.ConfigureNLog("nlog.config");

        if (env.IsDevelopment()) {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
            app.UseBrowserLink();
        } else {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseDefaultFiles();
        app.UseStaticFiles();
        app.UseIdentity();

        // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
        app.UseMvcWithDefaultRoute();
        //app.UseMvc(routes => {
        //    routes.MapRoute(
        //        name: "default",
        //        template: "{controller=Home}/{action=Index}/{id?}");
        //});

        // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
        try {
            using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
                .CreateScope()) {
                serviceScope.ServiceProvider.GetService<ChurBaseContext>()
                     .Database.Migrate();

                var userManager = serviceScope.ServiceProvider.GetService<UserManager<ChurchMember>>();
                var roleManager = serviceScope.ServiceProvider.GetService<RoleManager<IdentityRole>>();

                serviceScope.ServiceProvider.GetService<ChurBaseContext>().EnsureSeedData(userManager, roleManager);
            }
        } catch { }
    }
Run Code Online (Sandbox Code Playgroud)

jay*_*bro 5

当我在 Startup.cs 中的 UseMvc() 上方设置 Use() 扩展时,我有这种行为,它没有调用“await next();” 在函数的最后。

app.Use(async (context, next) =>
{
    // some custom magic

    await next();// don't forget this
});

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)


Bac*_*tnz 0

app.UseMvcWithDefaultRoute(); //in startup.cs
Run Code Online (Sandbox Code Playgroud)

或者

app.UseMvc(routes =>
{
  routes.MapRoute(
    name: "default",
    template: "{controller}/{action}/{id?}",
    defaults: new { controller = "Home", action = "Index" });
});
Run Code Online (Sandbox Code Playgroud)