当前位置:编程学习 > asp >>

asp.net mvc 3 获取路由领域名

---------------------------------------------------------------------------------------------------
 
一、注册路由 
 
  public class SysAreaRegistration : AreaRegistration
  {
 
    /// <summary>
 
    /// MVC 路由领域名称
    /// </summary>
    public override string AreaName
    {
      get
      {
        return "Sys";
      }
    }
 
 
    public override void RegisterArea(AreaRegistrationContext context)
    {
      string[] controllerNamespaces = new string[] { "Grass.Sys.Controllers" };
      context.MapRoute(
        "Sys_default",
        "Sys/{controller}/{action}",
        new { controller = "Login", action = "Index" },
        null,
        controllerNamespaces
      );
    }
  }    
----------------------------------------------------------------------------------------------------
 
二、获取路由领域名 
 
    /// <summary>
 
    /// MVC 路由领域名称
    /// </summary>
    public static string AreaName
    {
      get
      {
        HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current);
        RouteData rd = RouteTable.Routes.GetRouteData(httpContext);
        return rd.DataTokens["area"].GetString();
      }
    }
补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,