之间是不同的./,../,../../〜/在asp.net文件路径(URL) [英] Different between ./ , ../ , ../../ , ~/ on file path(URL) in asp.net

查看:92
本文介绍了之间是不同的./,../,../../〜/在asp.net文件路径(URL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本文件。

 <脚本SRC =〜/脚本/ angular.js>< / SCRIPT>

请参阅路径是〜/ SCRIPT 。但是,如果我进入 ../../ 而不是〜/ ,而且这个过程正在努力一样。

我的网站网址,如: https://sample.com/Scripts/angular.js

如果我进入 ../../ 之前脚本,然后它会自动改变previous网址(https://sample.com/Scripts/angular.js)


  

的网址是什么过程?而如何可以将其自动变化?和请告诉之间不同 ./,../,../../〜/,/脚本,脚本



解决方案

这些路径组件与特定的含义的快捷方式:


  • 表示当前路径级别(所以,如果你在的Index.aspx 和您引用 ./的style.css 则后者必须是在同一文件夹作为前)

  • .. 表示一个路径水平提高(所以,如果你在 /somefolder/index.aspx 和您引用 ../的style.css 则后者将必须在父文件夹 someFolder

  • / 指根级别(所以 /style.css 相同 http://www.mysite.com/style.css

  • 在ASP.NET意味着服务器端应用程序根目录(所以〜/的Index.aspx 会翻译成的Index.aspx 的URL文件,该文件在应用程序的根目录)

有许多事情,这里要注意:


  • 服务器的路径和的客户的路径之间的差异。例如,从网络浏览器的角度看有没有应用程序的根。 Web浏览器将不知道如何处理做的。只能在其中是$ P $对处理中的服务器端组件的路径可以使用。然后,服务器端组件将知道它转换成基于应用相对于所述web服务器的当前位置的客户端可见的路径。

  • 父路径说明符( .. )没有限制。在根目录的父被认为是根。所以,如果你的 http://www.mysite.com/someFolder/index.aspx 和您引用 ../../。 ./../的style.css 将进入 http://www.mysite.com/style.css

  • 浏览器也意味着你的路径。这其中的页面源代码和之间的差异之一DOM。您的网页源代码可能要 ../ SomePage.aspx页面的引用,但是当你将鼠标悬停在它用鼠标浏览器表明它是 HTTP: //www.mysite.com/somePage.aspx 。这是因为浏览器已经把的相对路径的前进入的绝对路径的后者。

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?

解决方案

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.

这篇关于之间是不同的./,../,../../〜/在asp.net文件路径(URL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆