Joset
Joset

Reputation: 81

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 { }
    }

Upvotes: 5

Views: 9427

Answers (5)

George
George

Reputation: 31

When you see just a blank page and have no response other that the blank page, it can be caused by many things. These are two that I have seen:

  1. A corrupt web.config
  2. A web.config that is clashing with IIS. This could happen when a particular section is locked in your IIS configuration.

Upvotes: 0

DotnetShadow
DotnetShadow

Reputation: 778

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

Upvotes: 3

jaybro
jaybro

Reputation: 1573

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?}");
});

Upvotes: 5

Sanket
Sanket

Reputation: 20047

This may happened because, you have not used MVC into execution pipeline.

In Configure method of startup class, you need to add like this-

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            ......

            app.UseStaticFiles();

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

or add UseMvcWithDefaultRoute like this-

app.UseMvcWithDefaultRoute();

This basically adds MVC to the IApplicationBuilder request execution pipeline.

See if this helps.

Upvotes: 0

williamsandonz
williamsandonz

Reputation: 16430

app.UseMvcWithDefaultRoute(); //in startup.cs

or

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

Upvotes: 0

Related Questions