Dan*_*iel 5 css asp.net-mvc routes
我正在尝试使用 mvc.net 中的路由向我的应用程序添加一个区域。对于控制器我添加:
routes.MapRoute(
"Area1", // Route name
"Area1/{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)
我如何以相同的方式路由 css/js 文件,即我想要去area1/content/site.css或 /content/site.css去/content/area1/site.css .
谢谢
我没有找到使用 mvc 路由来做到这一点的方法,我最终做的是:我在 http 模块中运行了这段代码:
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication Application = sender as HttpApplication;
var match = r.Match(Application.Request.Url.AbsolutePath);
if (match.Success)
{
var fileName = match.Groups[2].Value;
Application.Context.RewritePath("/" + fileName);
}
}
Run Code Online (Sandbox Code Playgroud)
r 在我的例子中是一个正则表达式:
private readonly Regex r = new `Regex("^/gmail(/canvas)?/((content|scripts|images|tinymce).*)$", RegexOptions.IgnoreCase);`
Run Code Online (Sandbox Code Playgroud)
在 global.asax 中我添加了:
routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(css|js|gif|jpg)(/.*)?" });
Run Code Online (Sandbox Code Playgroud)
阻止 mvc.net 路由这些请求。
可能还需要设置 iis6/iis7 通过 mvc.net 将请求路由到静态文件,但我忘记了详细信息。
我从几篇我不记得的帖子中选择了这个方法,所以我很抱歉我无法给予适当的信任。
| 归档时间: |
|
| 查看次数: |
4440 次 |
| 最近记录: |