Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net core mvc displays empty page

Please, I need help with a nagging issue with an asp.net core mvc app.

The app only shows blank home page - no contents at all including html markups. No controller is invoked even by typing url directly on the browser and no error is displayed.

I've created new app all over again a couple of times with the same result. Also, I've added statements below to the Configure method in the Startup class to no avail.

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

Any guide to resolve this mystery would be highly appreciated.

Thanks.

 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 { }
    }
like image 415
Joset Avatar asked Dec 16 '16 00:12

Joset


2 Answers

I had this behavior when I setup a Use() extension in the Startup.cs, above the UseMvc(), that did not invoke "await next();" at the end of the function.

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?}");
});
like image 108
jaybro Avatar answered Nov 19 '22 10:11

jaybro


You can try adding, either:

app.UseStatusCodePages();

or

app.UseStatusCodePagesWithReExecute("/error/{0}");

For info on the latter you can see: [When using UseStatusCodePagesWithReExecute, statuscode is not sent to browser

like image 2
DotnetShadow Avatar answered Nov 19 '22 11:11

DotnetShadow