Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
136 views
in Technique[技术] by (71.8m points)

c# - Different between ./ , ../ , ../../ , ~/ on file path(URL) in asp.net

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

These path components are shortcuts with specific meanings:

  • . means the current path level (so if you're on index.aspx and you reference ./style.css then 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.aspx and you reference ../style.css then the latter would have to be in the parent folder of someFolder)
  • / means the root level (so /style.css is the same as http://www.mysite.com/style.css)
  • ~ in ASP.NET means the server-side application root (so ~/index.aspx would be translated to the URL of the index.aspx file 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 on http://www.mysite.com/someFolder/index.aspx and you reference ../../../../style.css it will go to http://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's http://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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...