Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get host name in webapi method

I want to get website url into my webapi method. e.g my website name is abc.com and my api method url is xyz.com/getdetails?a=1 now on my webapi controller i want to get abc.com url to identify from this method was called.

like image 313
farrukh aziz Avatar asked Oct 22 '25 15:10

farrukh aziz


1 Answers

You get some complete information along with port on which the api is hosted. But you will need to add System.Web to make it work.

HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/');
like image 56
Himanshu Patel Avatar answered Oct 25 '25 05:10

Himanshu Patel