I have a script file .
<script src="~/Scripts/angular.js"></script>
See the path is ~/Script. But if I Entered ../../ instead of ~/,Also the process are working same .
My website URL like : https://sample.com/Scripts/angular.js
If I entered ../../ in before Scripts ,then it’s automatically change previous URL(https://sample.com/Scripts/angular.js) .
What is the url process ? And how can its automatically changed? and please tell about the Different between
./, ../ , ../../ , ~/ ,/Scripts ,Scripts?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
These path components are shortcuts with specific meanings:
.means the current path level (so if you’re onindex.aspxand you reference./style.cssthen the latter would have to be in the same folder as the former)..means one path level up (so if you’re on/somefolder/index.aspxand you reference../style.cssthen the latter would have to be in the parent folder ofsomeFolder)/means the root level (so/style.cssis the same ashttp://www.mysite.com/style.css)~in ASP.NET means the server-side application root (so~/index.aspxwould be translated to the URL of theindex.aspxfile that’s in the application’s root)
There are a number of things to note here:
- There is a difference between server paths and client paths. For example, from the web browser’s perspective there’s no “application root.” A web browser wouldn’t know what to do with
~. That can only be used in paths which are pre-processed in server-side components. The server-side components would then know to translate that into a client-visible path based on the current location of the application relative to the web server. - Parent path specifiers (
..) have no limit. The root’s parent is considered the root. So if you’re onhttp://www.mysite.com/someFolder/index.aspxand you reference../../../../style.cssit will go tohttp://www.mysite.com/style.css. - The browser also translates paths for you. This is one of the differences between the “page source” and the “DOM.” Your page source may have a reference to
../somePage.aspx, but when you hover over it with your mouse the browser indicates that it’shttp://www.mysite.com/somePage.aspx. This is because the browser has converted the relative path of the former into the absolute path of the latter.
Method 2
Let’s see…
. = this directory .. = the parent directory ../ = the parent directory ~/ = the user's home directory or the application's, in ASP / = the root directory ../../ = the parent's parent directory
and so on.
BTW, this works for all Linux/Unix systems.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0