Home > Software design >  How to change the url of a .net 6 web api
How to change the url of a .net 6 web api

Time:06-25

i wanted to change the launching url of the WebAPI from https://localhost:7027/controller to https://localhost:7027/test/controller. i have tried adding app.UsePathBase("/test") but it only routes swagger. i tried it with postman and it says 404 not found. how do i go about accomplishing this please. thank you

CodePudding user response:

You can do that with attribute routing for a specific controller or

[Route("test/[controller]")]
public class ValuesController : Controller
{

Or globally you can do like below

  app.UseEndpoints(endpoints =>
  {
        endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}");
  });

See below - Change the "/api" part of the url in ASP.Net Core

  • Related