样式表路径中的斜线 (/) 与波浪号斜线 (~/) [英] Slash (/) vs tilde slash (~/) in style sheet path
问题描述
ASP.NET 提供了两种指定样式表路径的方法:
ASP.NET offers two ways to specify paths for style sheets:
<link href="/common/black_theme/css/style.css" rel="stylesheet"> (this is working)
<link href="~/common/black_theme/css/style.css" rel="stylesheet"> (this is not working)
- 这些路径是如何解析的?
- 为什么生成的路径不同?
- 在这种情况下我应该选择哪个?
/
- 网站根目录~/
- 应用的根目录/
- Site root~/
- Root directory of the application
据我所知,~
代表应用程序的根目录.common"是IIS中网站根目录下的文件夹(名为testsite.demo
).
As per my knowledge, ~
represents the root directory of the application.
"common" is the folder below the website root (named testsite.demo
) in IIS.
物理路径:D:PhysicalpathWarpFirstSite estsite.demo
common"文件夹:D:PhysicalpathWarpFirstSite estsite.democommon
推荐答案
不同之处在于,如果您的网站是:
The difference is that if you site is:
http://example.com
并且您有一个应用程序 myapp
:
And you have an application myapp
on:
http://example.com/mydir/myapp
/
将返回站点的根目录(http://example.com
),
/
will return the root of the site (http://example.com
),
~/
将返回应用程序的根目录 (http://example.com/mydir/
).
~/
will return the root of the application (http://example.com/mydir/
).
这篇关于样式表路径中的斜线 (/) 与波浪号斜线 (~/)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!