Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET 4 URL路由Web表单打破了我对样式、脚本、图像等的相对路径_Asp.net_Asp.net Mvc_Url Routing_Asp.net Mvc Routing_Webforms - Fatal编程技术网

ASP.NET 4 URL路由Web表单打破了我对样式、脚本、图像等的相对路径

ASP.NET 4 URL路由Web表单打破了我对样式、脚本、图像等的相对路径,asp.net,asp.net-mvc,url-routing,asp.net-mvc-routing,webforms,Asp.net,Asp.net Mvc,Url Routing,Asp.net Mvc Routing,Webforms,我有一个应用程序,在默认的.aspx中有这样的链接 <link href="Styles/smoothness/jquery-ui-1.8.14.custom.css" rel="stylesheet" type="text/css" /> <script src="Scripts/json2.min.js" type="text/javascript"></script> <script src="Scripts/jquery-1.6.2.min.js

我有一个应用程序,在默认的.aspx中有这样的链接

<link href="Styles/smoothness/jquery-ui-1.8.14.custom.css" rel="stylesheet" type="text/css" />
<script src="Scripts/json2.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.8.14.custom.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.tmpl.min.js" type="text/javascript"></script>  

我是否可以在此处添加一些内容,使我的相对路径能够正常运行,而不必更改站点中的所有路径?

您可以使用global.asax中的路由。IgnoreRoute来排除引用静态内容的路由:

routes.IgnoreRoute("Styles/{*pathInfo}");
routes.IgnoreRoute("Scripts/{*pathInfo}");
routes.IgnoreRoute("Images/{*pathInfo}");

等等。

您可以简单地使用html基本标记

在aspx中:

<base id="baseControl" runat="server" />

希望这能有所帮助。

显然是的,但符号有点不同:在发生这种情况时,我突然意识到这是一个客户端问题,所以解决这一问题的唯一方法就是代码本身。我将不得不从“Images/”的相对引用转移到“/Images/”或者,我必须在这些链接周围包装服务器端代码,并在它们在浏览器中爆炸之前对它们进行预处理,就像routes一样。IgnoreRoute是System.Web.Mvc命名空间中RouteCollectionExtensions类的一种方法。使用routes.Ignore for WebForm我希望我们能找到一个合适的解决方案。我的问题是,我的网站设置在虚拟目录中。因此,我必须添加“/vir dir name”,我真的不想这样做-/
<base id="baseControl" runat="server" />
protected void Page_Init(object sender, EventArgs e)
{
    baseControl.Attributes.Add("href", Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/"));
}