简单实际的方式分隔Admin 区域
2011-03-22 21:01
211 查看
Add these 9 lines of code to your app
Add a new route in your Global.asax.cs
Tada! You’re done! There’s one catch…
Controllers in the Admin area must start with the “Admin” prefix.
You then create appropriate folders for views as usual.
This is a bit of a hack, but I like the fact that it requires very little code and it’s very simple :) Also, it would be very easy to tweak this code to allow for general partitioning of controllers by prefix, so you could have a “Admin” area, a “Mobile” area etc.
public class AdminRouteHandler : IRouteHandler { public IHttpHandler GetHttpHandler(RequestContext requestContext) { RouteData routeData = requestContext.RouteData; routeData.Values["controller"] = "Admin" + requestContext.RouteData.GetRequiredString("controller"); return new MvcHandler(requestContext); } }
Add a new route in your Global.asax.cs
routes.Add( "AdminRoutes", // Route name new Route( "Admin/{controller}/{action}/{id}", // URL with parameters new RouteValueDictionary(new { controller="Video", action = "Index", id=""}), new AdminRouteHandler()) // Parameter defaults );
Tada! You’re done! There’s one catch…
Controllers in the Admin area must start with the “Admin” prefix.
You then create appropriate folders for views as usual.
This is a bit of a hack, but I like the fact that it requires very little code and it’s very simple :) Also, it would be very easy to tweak this code to allow for general partitioning of controllers by prefix, so you could have a “Admin” area, a “Mobile” area etc.
相关文章推荐
- javascript中的选择结构if和switch的简单使用方式及实际操作的易错点
- GridView加分隔线,最简单的方式实现网格
- 简单有效的JAXP方式操作XML文档工具类
- Android客户端post方式连接web(servlet)服务器实现简单登录
- 用最简单的方式在C#中使用多线程加速耗时的图像处理算法的执行(多核机器)。
- Linux下用文件IO的方式操作GPIO(/sys/class/gpio)简单易操作
- 肤色检测算法 - 基于不同颜色空间简单区域划分的皮肤检测算法
- APP中一种在Java层实现的简单守护进程方式
- el表达式简单的集合输出方式
- Fragment中调用父Activity中方法的简单方式
- 流方式文件读写(简单实现)
- 史上最简单的gpu版caffe安装方式(ubuntu17.04以上版本)
- 一种简单的方式实现Cocos2d-x 2.x版本按层级关系派发Touch事件
- 用 Java 技术创建 RESTful Web (服务 JAX-RS:一种更为简单、可移植性更好的替代方式)
- 最简单的Druid使用方式
- 从实际使用分析CSS引用方式的异同
- 三种简单的图片放大方式
- 事务处理的三种方式(简单小Demo)
- Bootstrap 栅格系统 学习总结 Bootstrap框架是如今最流行的前端框架之一,Bootstrap功能强大,简单易学,很符合实际应用场景。 只是Bootstrap的内容较多,新手
- mvc下ajax请求遇到session超时简单处理方式