public static void RegisterDefaultAreaRoute(this AreaRegistration reg, AreaRegistrationContext context) { context.MapRoute( $"{reg.AreaName}_DefaultHomeIndex", $"{reg.AreaName}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new[] { reg.GetType().Namespace + ".Controllers" } ); context.MapRoute( $"{reg.AreaName}_DefaultIndex", $"{reg.AreaName}/{{controller}}", new { action = "Index" }, new[] { reg.GetType().Namespace + ".Controllers" } ); context.MapRoute( $"{reg.AreaName}_Default", $"{reg.AreaName}/{{controller}}/{{action}}/{{id}}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new[] { reg.GetType().Namespace + ".Controllers" } ); }
/// <summary> /// 映射Area路由数据 /// </summary> /// <param name="area"></param> /// <param name="routes"></param> /// <param name="state"></param> public static void CreateContextAndRegister(this AreaRegistration area, RouteCollection routes, object state) { AreaRegistrationContext context = new AreaRegistrationContext(area.AreaName, routes, state); string thisNamespace = area.GetType().Namespace; if (thisNamespace != null) { context.Namespaces.Add(thisNamespace + ".*"); } area.RegisterArea(context); }
public static void RegisterArea(Type t, RouteCollection routes, object state) { AreaRegistration registration = (AreaRegistration)Activator.CreateInstance(t); AreaRegistrationContext context = new AreaRegistrationContext(registration.AreaName, routes, state); string tNamespace = registration.GetType().Namespace; if (tNamespace != null) { context.Namespaces.Add(tNamespace + ".*"); } registration.RegisterArea(context); }
private static void RegisterArea(AreaRegistration registration, object state) { var context = new AreaRegistrationContext(registration.AreaName, RouteTable.Routes, state); string ns = registration.GetType().Namespace; if (ns != null) { context.Namespaces.Add(string.Format("{0}.*", ns)); } registration.RegisterArea(context); }
private static void RegisterArea <T>(RouteCollection routes, object state) where T : AreaRegistration { AreaRegistration registration = (AreaRegistration)Activator.CreateInstance(typeof(T)); AreaRegistrationContext registrationContext = new AreaRegistrationContext(registration.AreaName, routes, state); string areaNamespace = registration.GetType().Namespace; if (!String.IsNullOrEmpty(areaNamespace)) { registrationContext.Namespaces.Add(areaNamespace + ".*"); } registration.RegisterArea(registrationContext); }
private static void RegisterArea <T>(RouteCollection routes, object?state) where T : AreaRegistration { AreaRegistration registration = (AreaRegistration)Activator.CreateInstance(typeof(T)); AreaRegistrationContext context = new(registration.AreaName, routes, state); string typeNamespace = registration.GetType().Namespace; if (typeNamespace != null) { context.Namespaces.Add(typeNamespace + ".*"); } registration.RegisterArea(context); }
public static List <Type> GetControllersByArea(AreaRegistration area) { //AreaRegistration area = Areas.Where(a => a.AreaName.Equals(areaName)).FirstOrDefault(); List <Type> controllers = GetControllers(); //controllers = controllers.Where(t => t.GetCustomAttributes(typeof(AreaAttribute), true).Count() > 0).ToList(); controllers = (from c in controllers from a in c.GetCustomAttributes(typeof(AreaAttribute), true).Cast <AreaAttribute>() where (a.Registration.Equals(area.GetType())) //&& (c.GetCustomAttributes(typeof(Display)) select c).ToList(); return(controllers); }
private static void RegisterArea(AreaRegistration areaRegistration) { Sitecore.Diagnostics.Log.Info("Started RegisterArea", " RegisterArea "); var context = new AreaRegistrationContext(areaRegistration.AreaName, RouteTable.Routes); string @namespace = areaRegistration.GetType().Namespace; if (@namespace != null) { context.Namespaces.Add(@namespace + ".*"); } areaRegistration.RegisterArea(context); Sitecore.Diagnostics.Log.Info("Ended RegisterArea", " RegisterArea"); }
public static string[] GetNamespace(this AreaRegistration area, object namespacelocator = null) { var name = ""; if (namespacelocator != null) { name = namespacelocator.GetType().FullName; } else { name = area.GetType().FullName; } var dotIndex = name.IndexOf("."); if (dotIndex > 0) { name = name.Substring(0, dotIndex); } var result = new string[] { $"{name}.Areas.{area.AreaName}.Controllers", $"{name}.Areas.{area.AreaName}.Models" }; return(result); }
public string GetAreaName(AreaRegistration registration) { return(registration.GetType().Name.Replace("AreaRegistration", string.Empty)); }