惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 聂微东
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
C
Check Point Blog
M
MIT News - Artificial intelligence
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
大猫的无限游戏
大猫的无限游戏
D
Docker
Last Week in AI
Last Week in AI
IT之家
IT之家
F
Fortinet All Blogs
A
About on SuperTechFans
P
Proofpoint News Feed
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog RSS Feed
博客园_首页
月光博客
月光博客
博客园 - 司徒正美
Y
Y Combinator Blog

博客园 - Sphix

根据银行卡获取银行卡开户银行和类型 HTTP could not register URL http://+:8000/testservice/. Your... 一些必不可少的Sublime Text 2插件 C# CultureInfo列表 解决"There is already an open DataReader associated with this Command which must be closed first." exception in EF 中 C#正则表达式整理备忘 Lucene.net 开发记录 在Asp.net 4.0 中动态注册HttpModule ASP.net 视频上传转换flv并且抓取第一帧生成图片源码 揭秘全球最大网站Facebook背后的那些软件 asp.net网站管理工具 的 地址(Web Site Administration Tool ) Sql Server 2008 Full-text search Error: Word breaking timed out for the full-text query string. Associations in EF Code First CTP5: Part 1 – Complex Types C# Enum 类型的本地化 wordpress 文章缩略图功能 EF4 中Self-track entity 错误用于单web开发中要注意的地方 C#验证文件类型 Asp.net文件下载 SQLite 资源汇总
简单实际的方式分隔Admin 区域
Sphix · 2011-03-22 · via 博客园 - Sphix
  1. Add these 9 lines of code to your app

    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);
            }
    }      
  2. 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.

File Names Start With Admin

You then create appropriate folders for views as usual.

View folders work 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.