zoukankan      html  css  js  c++  java
  • 简单实际的方式分隔Admin 区域

    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.

    披荆斩棘,朝自己的信仰!Go on
  • 相关阅读:
    壁纸网站收藏
    LaTeX公式学习
    最简单的音乐播放器,实现播放器基本功能
    计算机视觉领域的牛人博客、研究机构、博客
    视频压缩编码和音频压缩编码的基本原理
    MPEG-4 压缩编码标准
    视频编码标准简介
    视频压缩编码的基本原理
    数字视频原理
    视频压缩编码综述
  • 原文地址:https://www.cnblogs.com/lyk831216/p/1991844.html
Copyright © 2011-2022 走看看