How to change the default controller and action in ASP.NET Core API?

前端 未结 2 503
渐次进展
渐次进展 2021-02-08 02:33

I\'m creating an ASP.NET Core API app, and currently, and when one creates a new project there is a controller named Values, and by default the API opens it when you run. So, I

相关标签:
2条回答
  • 2021-02-08 03:04

    You can change it in launchSettings.json file in Properties node. There should be field launchUrl which contains default launching url

    0 讨论(0)
  • 2021-02-08 03:06

    With later version of ASP .Net Core, MVC routing is less prominent than it once was, there is general routing now in place which can handle routing of Web APIs, MVC and SignalR amongst other kinds of routes.

    If you are using later versions, and not specifically calling app.UseMvc you can do this with the generalised Endpoints configuration:

    app.UseEndpoints(endpoints =>
    {
       endpoints.MapControllerRoute("default", "{controller=Account}/{action=login}/{id?}");
      // Create routes for Web API and SignalR here too...
    });
    

    Where Account and login are your new default controller and actions. These can be MVC or Web API controller methods.

    0 讨论(0)
提交回复
热议问题