我想完全理解如何在静态和动态文件中使用相对和绝对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
这是我的静态网页地址(我想显示一些图片并运行一些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地址应该是?