我想完全了解如何在静态和动态文件中使用相对和绝对的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地址?

有帮助吗?

解决方案

你的方法是犯规的。尝试顺序处理文件。请记住,无论如何,您需要写它,所以试试这个:

(打开读取的文件,打开写入的新文件)

  1. readline - >字符串变量
  2. 如果阅读线是您的预订,请阅读下一行而不进行任何操作。
  3. 如果不是2)然后将行写入新文件。
  4. 刷新新文件并关闭两个。
  5. 删除旧文件并将新名称移动到旧名称。

    完成。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top