60

I have created an empty Web Application in .NET Core, in wwwroot I have the index.html which is not loading as default page, it loads only when I call it explicitly.

Here is my project.json

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

Here my Startup:

public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app)
    {
        app.UseStaticFiles();
    }

    // Entry point for the application.
    public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}

2 Answers 2

128

You have to add

app.UseDefaultFiles();

before app.UseStaticFiles(); in Configure method.

See documentation for more details.

Sign up to request clarification or add additional context in comments.

5 Comments

Good one! You are right. It's working and the order plays a big role, what I dislike, but...
Here is additional information. For example which library to add, and which order. talkingdotnet.com/make-index-html-startup-file-in-aspnet-core
Is there a page where we can see, which middleware has to be called when? Or, just google it all...
For my case root of problem was using UseDefaultFiles after UseMvc
Working through a tutorial i wanted to add a html file. I first placed foo.html under the folder /pages/ but it did not show up. Moving it to /wwwroot/ did the trick.
-12

Another way to do it is to edit your web.config file. Add there new rules, corresponding your needs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.