在asp.net的样式表path中使用斜线(/)和波浪线斜线(〜/)
如何在asp.net中解决这两个path。 为什么这两个给出不同的path。 我们什么时候需要去这些。
<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)
据我所知〜表示应用程序根目录“Common”是IIS网站(名为testsite.demo)根目录下的文件夹
物理path= D:\Physicalpath\WarpFirstSite\testsite.demo常用文件夹位置 – D:\Physicalpath\WarpFirstSite\testsite.demo\common
-
/– 网站的根 -
~/– 应用程序的根目录
不同的是,如果你的网站是:
http://example.com
你有一个应用程序myapp :
http://example.com/mydir/myapp
/会返回网站的根目录( http://example.com ),
~/将返回应用程序的根目录( http://example.com/mydir/ )。
第二个将无法正常工作,因为它不是除了服务器端的asp.net代码之外的任何认可的path。 由于你的链接标签是正常的HTML而不是服务器控件,它永远不会得到处理。
如果你添加runat="server"在你的链接标签,那么它会完美的工作….
喜欢这个….
<link href="~/common/black_theme/css/style.css" rel="stylesheet" runat="server">
(这也是工作)