How do I get the base URL using javascript?
E.g., When I browse my site from visual studio, and if my URL is http://localhost:20201/home/index
, I would want to get http://localhost:20201
If I host my site on IIS, and if my virtual directory name is MyApp and the URL is http://localhost/MyApp/home/index
, I would want to get http://localhost/MyApp
I tried using location.protocol
+ location.hostname
(and location.host
), they work fine when i browse my site via visual studio, but when I host it on IIS, I get http://localhost
, the /MyApp is truncated off.