如何将html中的所有链接定向到网站的根文件夹? [英] How to direct all the links in html to the root folder of the website?

查看:208
本文介绍了如何将html中的所有链接定向到网站的根文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于系统要求我在公司的服务器下开发网站,所以我发现很难将资源重定向到该网站的根目录。如果我使用 /指定根目录,则所有javascript,图像和CSS文件都可以在localhost中完美使用。但是,如果我尝试连接到公司的服务器,则所有失败,因为包含该网站所有资料的文件夹只是该服务器的子目录。我试图使用base链接到根
。它适用于javascript和图像,但是以某种方式无法使用css文件。当我使用inspect元素时,css的链接似乎是../../stylesheet/some.css,而javascript的源似乎是javascript / master.js。我想知道是否有人可以帮助我解决该问题,因为该网站的子文件夹数量非常复杂,并且我无法使用.. / .. / .. / ....来引用资源。下面是我的项目的结构。

Since I am asked to develop a web site under company's server, I find it hard to redirect resources to the root of that website. If I use "/" to specify the root directory, all javascripts, images and css files could be used perfectly in localhost. However, if I try to connect to company's server, everything fails since the folder containing all the materials of that web site is only a subdirectory of that server. I tried to use base to link to the root . It works for javascript and images but somehow css files cannot be used. When I use inspect element, the link of css appears to be ../../stylesheet/some.css while source of javascript appears to be javascript/master.js. I wonder if some one could help me solve the problem since the web site is quite complicated in terms of number of subfolders and it is not possible for me to use ../../../.... to refer to resources. Below is the structure of my project.

推荐答案


  1. In。 aspx
    使用HttpRequest.ApplicationPath(参考 MSDN


< script runat = server>
受保护的void Page_Load(对象发送者,EventArgs e)
{
Label1.Text = Request.ApplicationPath;
Image1.ImageUrl = Request.ApplicationPath + /images/Image1.gif;
Label2.Text = Image1.ImageUrl;
}
< / script>

在.cs
中使用Server.MapPath (〜/ bin)

In .cs Use Server.MapPath("~/bin")

这篇关于如何将html中的所有链接定向到网站的根文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆