Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get root url path

I'm searching a way to get the root URL of my Web project; as example:

Local:

http://localhost:52390/pages/user.aspx

Expected result: http://localhost:52390

IIS:

http://lst.pg.com/iLearn/pages/user.aspx

Expected result: http://lst.pg.com/iLearn

Exists a way to achieve this in ASPX? Or in Javascript/jQuery?

like image 582
MiBol Avatar asked Sep 01 '16 18:09

MiBol


People also ask

How do I find the root URL?

You can determine your server's root URL by browsing to a page on your website and observing the address in the location/address entry field of the browser. The root URL is the section between the colon-slash-slash (://) and the next slash (/), omitting any port number (:portno).

What does root URL mean?

A root URL is the start or index page of a domain on a web server. Colloquially, many users call the homepage the “root URL” as well.


2 Answers

in javascript you can get url information from the location object.

var href = location.href; //returns the entire url
var host = location.hostname; //returns just the hostname of the url.
like image 79
Troy Harris Avatar answered Nov 15 '22 03:11

Troy Harris


ASPX: Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath

Implemented with Javascript:

<script type="text/javascript">
    var rootUrl = '<% =(Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath) %>';
</script>
like image 44
MiBol Avatar answered Nov 15 '22 03:11

MiBol