./, ../, ../../, ~/在asp.net中的文件路径(URL)之间的区别 [英] Different between ./ , ../ , ../../ , ~/ on file path(URL) in asp.net

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

问题描述

我有一个脚本文件.

<script src="~/Scripts/angular.js"></script>

看到的路径是~/Script.但是如果我输入 ../../ 而不是 ~/,那么这个过程也是一样的.

See the path is ~/Script. But if I Entered ../../ instead of ~/,Also the process are working same .

我的网站 URL 像:https://sample.com/Scripts/angular.js

My website URL like : https://sample.com/Scripts/angular.js

如果我在 Scripts 之前输入 ../../ ,那么它会自动更改以前的 URL(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) .

url 过程是什么?它如何自动更改?并请谈谈 ./, ../, ../../, ~/,/Scripts ,Scripts 之间的区别?

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:

  • . 表示当前路径级别(因此,如果您在 index.aspx 上并引用 ./style.css 然后后者必须与前者在同一个文件夹中)
  • .. 表示向上一级路径(因此,如果您在 /somefolder/index.aspx 上并引用 ../style.css 那么后者必须在 someFolder) 的 父文件夹
  • / 表示根级别(所以 /style.csshttp://www.mysite.com/style.css 相同代码>)
  • ~ 在 ASP.NET 中表示服务器端应用程序根目录(因此 ~/index.aspx 将被转换为 index.aspx 应用程序根目录中的文件)
  • . 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:

  • 服务器路径和客户端路径是有区别的.例如,从 Web 浏览器的角度来看,没有应用程序根".Web 浏览器不知道如何处理 ~.这只能用于在服务器端组件中预处理的路径.然后,服务器端组件将知道根据应用程序相对于 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.这是因为浏览器已经将前者的相对路径转换成了后者的绝对路径.
  • 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天全站免登陆