区域中 aspx 文件中的 href 路径
我正在不断测试 ASP.NET MVC 2 Preview 2 的新功能,称为“一个项目内的区域”。 目前,我在从 aspx 代码链接到 css 和 js 文件时遇到问题。
当 url 指向没有 id 的 url 时,一切正常:
当 url 包含参数:
然后页面无法从 /content 和 /scripts 找到 css 和 js 文件。
我认为问题与路由有关。我设置了标准路由规则,例如:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
AreaRegistration.RegisterAllAreas();
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
在该区域的路由配置中:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
}
aspx 文件中的示例资源 href:
<link href="../../Content/datatables.css" rel="stylesheet" type="text/css" />
任何人都可以提出解决方案来解决错误资源 href 的问题吗?
I am continually testing the new feature of ASP.NET MVC 2 Preview 2 called: "Areas within one project".
Currently I have a problem with linking to css and js files from within aspx code.
When the url points to an url without the id, everything works fine:
The problem appears when the url contains the parameter:
then the page cannot find css and js files from /content and /scripts.
I think the problem is related to routing. I have standard routing rules set, eg:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
AreaRegistration.RegisterAllAreas();
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
and in the area's route config:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
}
An example resource href in aspx file:
<link href="../../Content/datatables.css" rel="stylesheet" type="text/css" />
Can anyone suggest a solution to resolve the problem of bad resource href?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用 URL 路由时,您事先并不知道 URL 中会有多少/多少/路径/部分。因此,您根本无法使用路径相对 URL:您不知道需要多少个“..”段。
相反,请使用根 URL:
如果您的应用程序可以安装在非根 URL 上(例如,在您的某个区域下),则必须将该区域名称作为根 URL 的一部分输出。(大概是这样)这是使用
AreaRegistrationContext.AreaName
获得的。)When you are using URL routing, you don't know how/many/path/parts there are going to be in your URL in advance. So you can't use path-relative URLs at all: you don't know how many ‘..’ segments you are going to need.
Instead, use rooted URLs:
If your application can be mounted on a non-root URL (eg. under one of your
area
s, you must output that area name as part of the rooted URL. (Presumably this is obtained usingAreaRegistrationContext.AreaName
.)怎么样,设置 runat="server" 属性。
How about this, set runat="server" attribute.