5

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 { }
    }
Joset
  • 81
  • 2
  • 5

5 Answers5

5

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?}");
});
jaybro
  • 1,363
  • 1
  • 12
  • 23
2

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

DotnetShadow
  • 748
  • 1
  • 10
  • 28
0
app.UseMvcWithDefaultRoute(); //in startup.cs

or

app.UseMvc(routes =>
{
  routes.MapRoute(
    name: "default",
    template: "{controller}/{action}/{id?}",
    defaults: new { controller = "Home", action = "Index" });
});
williamsandonz
  • 15,864
  • 23
  • 100
  • 186
  • I have everything in place as mentioned but still experiencing the same issue. Not sure what I'm doing wrong, still. Thanks. – Joset Dec 16 '16 at 09:14
0

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.

Sanket
  • 19,295
  • 10
  • 71
  • 82
  • Also, check your browser console, you will see error like this- `Failed to load resource: the server responded with a status of 404 (Not Found)` – Sanket Dec 16 '16 at 06:53
  • Thanks for the quick response. I've setup everything as instructed but no difference. No error in the browser console as well. – Joset Dec 16 '16 at 09:13
  • Can you share complete configure method of startup? – Sanket Dec 16 '16 at 09:18
  • I just did. Thanks. – Joset Dec 16 '16 at 09:28
  • I have same issue. Everything works under Windows 10 with IISExpress, but not work on apache/centos. – Cheung Jul 20 '17 at 06:37
  • @Cheung I never tried with apache/centos. can you please raise new question with your details, so others can give you some inputs. – Sanket Jul 20 '17 at 08:25
0

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.
George
  • 21
  • 4