locked
Basepath of the .Net Core API RRS feed

  • Question

  • User1501362304 posted

    Hi,

    I want to get base path of web api core application. 

    So, if my api endpoint is https://localhost/onlineservice/api/users then I need to get https://localhost/onlineservice/ (this application is running under IIS).

    If it is running under iis express and on a port then get the url with port, right before api/.
    Have seen many examples of .net core mvc but found nothing relevant to .net core api.  

    Sunday, February 28, 2021 4:39 PM

All replies

  • User1120430333 posted

    You have actually done the WebAPI deployment to IIS? You set the port number the WebAPI is to be listening on?

    Deploy ASP.NET Core API application In IIS (c-sharpcorner.com)

    The URL regardless of it being hosted on IIS Express or IIS, the port number must be known as to what port the WebAPI is listening on.

    You can go to IIS Administration, go to a site and Actions/browse site, and it will show you the port number the Web program is listing on

    Sunday, February 28, 2021 5:25 PM
  • User1501362304 posted

    You have actually done the WebAPI deployment to IIS? You set the port number the WebAPI is to be listening on?

    I want to know api url programatically on Action method of web api controller, so that in future if I redeploy the API to another server, I don't have to change the API url in some config file to get the API base url. 

    Sunday, February 28, 2021 5:45 PM
  • User1120430333 posted

    You say you see many articles talking about how to do it for ASP.NET MVC Core. So why wouldn't they work for ASP.NET MVC WebAPI Core, since both are built on the same ASP.NET MVC Core pipeline. You can implement ASP.NET MVC Core views and controllers in a ASP.NET MVC WebAPI program.

    Are you talking about what is in the link? If you are, then I don't see why it would not work in an ASP.NET MVC WebAPI Core program.

    5 ways to set the URLs for an ASP.NET Core app (andrewlock.net)

    Sunday, February 28, 2021 8:27 PM
  • User475983607 posted

    I want to know api url programatically on Action method of web api controller, so that in future if I redeploy the API to another server, I don't have to change the API url in some config file to get the API base url. 

    You misunderstand a several fundamentals.  You'll never have localhost/application in the real world.  The client application needs to know the Web API domain not Web API.  If you're application hosts the UI and Web API then you already know the host.

    Sunday, February 28, 2021 9:02 PM