My endpoint routing is not working in my asp.net core 3.0 Api
. I have seen similar questions but I am still not sure what is missing here.
I have the following in Startup.cs
{
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.AddControllers()
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.Formatting = Formatting.Indented;
options.SerializerSettings.Converters.Add(
new Newtonsoft.Json.Converters.StringEnumConverter());
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
"test",
"api/v1.0/{controller}/{id?}");
});
}
}
My Ping controller
looks like:
public class PingController : ControllerBase
{
public IActionResult Get()
{
return Ok(true);
}
}
navigating to http://localhost//api/v1.0/Ping returns 404 page not found.
What am I missing here ? I also saw that MS suggests attribute routing for Web Apis but wanted to figure out why this is not working in the first place.