Asp.net

樣式表路徑中的斜線 (/) 與波浪線斜線 (~/)

  • June 21, 2011

ASP.NET 提供了兩種方法來指定樣式表的路徑:

<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)。

物理路徑:D:\Physicalpath\WarpFirstSite\testsite.demo

“common”文件夾:D:\Physicalpath\WarpFirstSite\testsite.demo\common

  • /- 網站根
  • ~/- 應用程序的根目錄

不同之處在於,如果您的網站是:

http://example.com

你有一個應用程序myapp

http://example.com/mydir/myapp

/將返回站點的根目錄 ( http://example.com),

~/將返回應用程序的根 ( http://example.com/mydir/)。

引用自:https://stackoverflow.com/questions/6424114