One my example how to start empty Asp.Net core project in Visual Studio 2019, and add one controller to it.
Start empty Asp.Net core project:
Choose ASP.NET Core Web Application:
Choose "Empty":
Since I am not using reSharper, I had to create "Controllers" folder manually. Open some file from solution and right click on tab and open containing folder:
Create new folder and name it "Controllers":
Your folder structure now should look like:
In "Controllers" folder in create new file, and Name it like EmptyController.cs, write something like
using Microsoft.AspNetCore.Mvc;
namespace AspDotNetCorePostExample.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class EmptyController : ControllerBase
{
[HttpGet]
public string Get()
{
return "Hello world";
}
}
}
In AspDotNetCorePostExample\AspDotNetCorePostExample\Startup.cs in method "Configure" delete:
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
Instead write:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
In ConfigureServices add services.AddControllers();
Start solution and go to like "https://localhost:44336/api/Empty" (just add /api/Empty)
If you like you can manually add wwwroot folder, and use him like I already explained
here.
Here is new Startup.cs, and to disable HTPPS go to project properties -> Debug -> uncheck "Enable SSL":