When I used This Template:
for an Angular Frontend .NET Backend. But when I created an API Controller like this in the Controller Directory:
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers
{
[Route("[controller]")]
[ApiController]
public class TestController : ControllerBase
{
[HttpGet]
public int Get()
{
return 0;
}
}
}
I always get 404 Not Found in Postman with query "https://localhost:44490/Test" even though the "WeatherForecastController" template that was already in the Project works fine. I tried the TestController in another Template that is just the .NET Backend and it works fine, I get a normal 200 back...
I also tried a 1 to 1 copy of the WeatherForecastController the Template came with but that also did not Work, I think the Program does not even get to the Controller so I guess there is something wrong with the routing setup. Im new to .Net so I might just have overseen something.
Any help is greatly appreciated.
This is the Program.cs that came with the Project:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
app.MapFallbackToFile("index.html");
app.Run();