Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC6 Default Page

Maybe I just been awake too many hours and totally overseeing something but I am using MVC6 ASP.NET 5.0 to develop an AngularJS website. Inside my wwwroot I have a index.html page and it was working just fine but then applied an update and now all of a sudden I just get a blank white screen: Developer Tools tells me:

Failed to load resource: the server responded with a status of 404 (Not Found)

Inside my startup I have the following:

public void Configure(IApplicationBuilder app)
{
    app.UseDefaultFiles(new Microsoft.AspNet.StaticFiles.DefaultFilesOptions() { DefaultFileNames = new[] { "index.html" } });
    app.UseMvc();
}

Some reason I am still getting a blank white page and nothing loading when I am debugging.

like image 812
kevin c Avatar asked Sep 17 '15 18:09

kevin c


People also ask

What is the default page in MVC?

asax file then BlogList is the default page for my site: routes.

How do I change the default page in ASP.NET MVC?

You can set up a default route: routes. MapRoute( "Default", // Route name "", // URL with parameters new { controller = "Home", action = "Index"} // Parameter defaults ); Just change the Controller/Action names to your desired default.


2 Answers

You must also specify app.UseStaticFiles(). From the docs:

In order for your Web app to serve a default page without the user having to fully qualify the URI, call the UseDefaultFiles extension method from Startup.Configure as follows. Note that you must still call UseStaticFiles as well. This is because UseDefaultFiles is a URL re-writer that doesn’t actually serve the file. You must still specify middleware (UseStaticFiles, in this case) to serve the file.

like image 66
Dave Zych Avatar answered Sep 22 '22 17:09

Dave Zych


Just to add to the answer above:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
  ...
  // Serve the default file, if present.
  app.UseDefaultFiles();
  app.UseStaticFiles();
  ...
}

http://docs.asp.net/en/latest/fundamentals/static-files.html

like image 20
kyle Avatar answered Sep 23 '22 17:09

kyle