简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM