title: Setting index.html as default page in asp.net core
body: <p>How can I get asp.net core to serve an index.html file from inside my wwwroot?</p>
  
  <p>The reason I want to do this is because I an developing an angular 4 app using the angular CLI and it takes care of the entire build process.  I have set it up to build into the wwwroot directory of my asp.net core project but asp.net core doesn't want to serve it.</p>
  
  <p>At first I tried to return the html file through a controller.  I tried this route:</p>
  
  <pre><code>app.UseMvc(routes =&gt;
      {
          routes.MapRoute(
              name: "default",
              template: "{controller=Home}/{action=Index}");
      });
  </code></pre>
  
  <p>And then in the controller I return the html file like this:</p>
  
  <pre><code>public IActionResult Index()
  {
      var webRoot = _env.WebRootPath;
      var path = System.IO.Path.Combine(webRoot, "index.html");
  
      return File(path, "text/html");
  }
  </code></pre>
  
  <p>This didn't work.  It returned a 404 not found exception and gave the path but the path it gave was the correct path to the index.html file (I cut and pasted it into explorer and the file opened).</p>
  
  <p>I am also declaring these in startup:</p>
  
  <pre><code>app.UseStaticFiles();
  app.UseDefaultFiles();
  </code></pre>
  
  <p>I then tried removing the default route.  Now I am able to get to the index.html file but only if I type the filename in, i.e.:</p>
  
  <blockquote>
    <p>localhost:58420/index.html</p>
  </blockquote>
  
  <p>If I try to access the root of the domain without the "index.html" specified I get a 404 error.</p>
  
  <p>What is the proper way to reference the index.html as the default page?  I am guessing doing it from a controller is probably better because then it will be compatible with angular routing without rewrites.</p>