0

I am playing around with web api in .NET 6. Everything works as expected. However, I am trying to load up a simple HTML/CSS landing page under wwwroot.

I wish to add that I never faced this issue, with .NET 3.0 or .NET 5 which had a similar configuration.

I have my Program.cs

app.UseSwagger();
app.UseSwaggerUI();    
app.UseHttpsRedirection();    
app.UseStaticFiles();    
app.UseAuthorization();    
app.MapControllers();    
app.Run();

Now, if I were to manually visit, localhost/index.html, I get the landing page, both locally and also when deployed on an azure web app.

However, if reach the localhost (or the deployed web app), index.html wont load like it usually does in older versions of .NET.

Am I missing something or is this like a bug?

The full project available here - https://github.com/Jay-study-nildana/CSharpForStudents/tree/main/WebApiDotNet6/DotNet6APIEFCoreSQLite

Note: I have looked at another similar question. I think, its not the same.

MVC 6, .NET Core RC2 Rewrite to index.html on non /api urls

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Jay
  • 2,648
  • 4
  • 29
  • 58
  • 3
    Sounds like you need to [set the default document](https://stackoverflow.com/questions/43090718/setting-index-html-as-default-page-in-asp-net-core) for your application. – Richard Deeming Nov 23 '21 at 11:44
  • @RichardDeeming That did it! Thanks. – Jay Nov 23 '21 at 14:05

1 Answers1

-1

You need to define routers and views in the controller methods

return View();
wangyou
  • 35
  • 4