静的ファイルと動的ファイルで相対URLアドレスと絶対URLアドレスを使用する方法を完全に理解したいと思います。
~ :
/ :
.. : in a relative URL indicates the parent directory
. : refers to the current directory
/ : always replaces the entire pathname of the base URL
// : always replaces everything from the hostname onwards
この例は、仮想ディレクトリなしで作業している場合は簡単です。しかし、私は仮想ディレクトリに取り組んでいます。
Relative URI Absolute URI
about.html http://WebReference.com/html/about.html
tutorial1/ http://WebReference.com/html/tutorial1/
tutorial1/2.html http://WebReference.com/html/tutorial1/2.html
/ http://WebReference.com/
//www.internet.com/ http://www.internet.com/
/experts/ http://WebReference.com/experts/
../ http://WebReference.com/
../experts/ http://WebReference.com/experts/
../../../ http://WebReference.com/
./ http://WebReference.com/html/
./about.html http://WebReference.com/html/about.html
仮想ディレクトリで作業している私のプロジェクトのように、以下のサイトをシミュレートしたいと思います。
これらは私のaspxおよびascxフォルダーです
http://hostAddress:port/virtualDirectory/MainSite/ASPX/default.aspx
http://hostAddress:port/virtualDirectory/MainSite/ASCX/UserCtrl/login.ascx
http://hostAddress:port/virtualDirectory/AdminSite/ASPX/ASCX/default.aspx
これらは私のJSファイルです(aspxファイルとascxファイルの両方で使用されます):
http://hostAddress:port/virtualDirectory/MainSite/JavascriptFolder/jsFile.js
http://hostAddress:port/virtualDirectory/AdminSite/JavascriptFolder/jsFile.js
これは私の静的Webページアドレスです(いくつかの写真を表示し、いくつかのjs関数内で実行したい):
http://hostAddress:port/virtualDirectory/HTMLFiles/page.html
これは私の画像フォルダです
http://hostAddress:port/virtualDirectory/Images/PNG/arrow.png
http://hostAddress:port/virtualDirectory/Images/GIF/arrow.png
ASPXファイルにファイルのリンクを書き込みたい場合は、次のように記述します。
aspxImgCtrl.ImageUrl = Server.MapPath("~")+"/Images/GIF/arrow.png";
しかし、ハードコードされたパスまたはjavascriptファイルからのパスを記述したい場合、どのようなURLアドレスにする必要がありますか?