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

2
  • 3
    Sounds like you need to set the default document for your application. Commented Nov 23, 2021 at 11:44
  • @RichardDeeming That did it! Thanks. Commented Nov 23, 2021 at 14:05

1 Answer 1

-1

You need to define routers and views in the controller methods

return View();
Sign up to request clarification or add additional context in comments.

2 Comments

No, they want to serve static files, not a Home/Index.cshtml view.
That is, I understand the mistake.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.