0

In c# Web API, I need to access the base address of the Web API URL.

I tried using

string applicationpath =  HttpContext.Current.Request.ApplicationPath;

but that did not work.

I used the IWebHostEnvironment, even it did not have enough information about it.

How do I access the url?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Venkat
  • 1,702
  • 2
  • 27
  • 47
  • 1
    In a controller action both the context and request are accessible as properties. Have you tried `this.Request.PathBase`, `this.Request.GetEncodedUrl()` or `this.Request.GetDisplayUrl()`? `HttpContext.Current` doesn't exist in ASP.NET Core. The HttpContext is no longer a singleton. – Panagiotis Kanavos Jun 30 '23 at 07:45

1 Answers1

0

Try this:

HttpContext.Current.Request.Url
amiry jd
  • 27,021
  • 30
  • 116
  • 215