加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 09:47:13 所属栏目:asp.Net 来源:网络整理
导读:我在default.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"/scriptscript src="Scripts/jquery-1.6.2.min.js
我在default.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>

一旦我添加了URL路由,它就破坏了我的相对路径.因此,如果我深入到一条路线,那么页面就找不到图像,脚本等.我想我的jQuery服务调用可能也会被破坏.除了在每个相对引用的开头添加“/”以解决此问题之外,还有其他方法吗?在我的global.asax我目前有……

void RegisterRoutes(RouteCollection routes)
{

    routes.MapPageRoute(
        "EntityRoute","{entityID}","~/Default.aspx");        

    routes.MapPageRoute(
        "GlobalSearchRoute","{entityID}/{guarantorID}/{guarDOB}","~/Default.aspx");
}

我可以在这里添加一些允许我的相对路径在不改变站点中所有路径的情况下运行的东西吗?

解决方法

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

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

等等

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读