In ASP.NET Core Web API I am using Attribute routing and I need to move it to conventional routing.
[ApiController]
public class HomeController : Controller
{
[Route("GetHome")]
[AllowAnonymous]
[HttpGet]
public string Getdeatils([FromBody] myclass cs, string system)
{
}
}
With Attribute routing the URL localhost/GetHome?system=abc works and triggers Getdeatils method.
I am trying to move same URL pattern to startup, but I am unable to achieve it.I have removed [ApiController] from controller class I have tried below code in startup. But it is not working.
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "mycustom",
pattern: "GetHome",
defaults: "{controller=Home}/{action=Getdeatils}/{system?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{system?}");
});
URL:localhost/Home/Getdeatils?system=abc - This works fine
URL:localhost/GetHome?system=abc - This is not working.
How this can be achieved without changing the URL format.