i am porting over an applciation written in netcore2 to 6 with angular 13. When running in visual studio i always get a 404 error for every web api controller / method
[ApiController]
[Route("[controller]")]
public class GetOptionsController : Controller
{
private readonly GetOptionsService _getOptionsService;
public GetOptionsController(GetOptionsService getOptionsService)
{
_getOptionsService = getOptionsService;
}
[HttpGet]
public IActionResult GetOptions()
{
var options = _getOptionsService.GetOptions();
return Ok(options);
}
}
}
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { IOption } from '../interfaces/option';
@Injectable()
export class OptionsService {
constructor(private http: HttpClient) { }
getOptions(): Observable<IOption[]> {
return this.http.get<IOption[]>("getoptions", { responseType: 'json' });
}
}
when creating the project i chose ASP.NET Core With Angular (maybe this wasnt the best choice?) and just added new api methods and angular components. all web apis return 404 (breakpoints in the controller are never hit) except WeatherForecastController that is created by default when the project is created. i dont see it doing anything different than im doing. this worked in the old project (core 2.0 with angular 6). POST methods dont work either.
i have been trying to figure this out for days and cant. can anyone help?