Asp.net core default route
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Main", action = "Index" });
routes.MapRoute(
name: "default",
template: "{controller=Main}/{action=Index}/{id?}");
These are the two ways of defining default route. You are mixing them. You need always to define a template. In the second way you can write the defaults directly in the template.
Another solution would be to redirect "/" to another url
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapGet("/", context =>
{
return Task.Run(() => context.Response.Redirect("/Account/Login"));
});
});
The easiest way for me (and without using MVC) was to set the controller to default route using empty [Route("")] custum attribute like so:
[ApiController]
[Route("")]
[Route("[controller]")]
public class MainController : ControllerBase
{ ... }
with Startup.Configure
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});