The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SubdomainRouteExtension.cs 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System.Web.Mvc;
  2. using System.Web.Routing;
  3. namespace Teknik
  4. {
  5. public static class SubdomainRouteExtension
  6. {
  7. public static SubdomainRoute MapSubdomainRoute(this RouteCollection routes, string name, string subDomain, string url, object defaults)
  8. {
  9. SubdomainRoute route = new SubdomainRoute(
  10. subDomain,
  11. url,
  12. new RouteValueDictionary(defaults),
  13. new MvcRouteHandler());
  14. routes.Add(AddSubToName(subDomain, name), route);
  15. return route;
  16. }
  17. public static SubdomainRoute MapSubdomainRoute(this RouteCollection routes, string name, string subDomain, string url, object defaults, object constraints)
  18. {
  19. SubdomainRoute route = new SubdomainRoute(
  20. subDomain,
  21. url,
  22. new RouteValueDictionary(defaults),
  23. new RouteValueDictionary(constraints),
  24. new MvcRouteHandler());
  25. routes.Add(AddSubToName(subDomain, name), route);
  26. return route;
  27. }
  28. public static SubdomainRoute MapSubdomainRoute(this RouteCollection routes, string name, string subDomain, string area, string url, object defaults, string[] namespaces)
  29. {
  30. SubdomainRoute route = new SubdomainRoute(
  31. subDomain,
  32. url,
  33. new RouteValueDictionary(defaults),
  34. new RouteValueDictionary(new { }),
  35. new RouteValueDictionary(new { Area = area, Namespaces = namespaces }),
  36. new MvcRouteHandler());
  37. routes.Add(AddSubToName(subDomain, name), route);
  38. return route;
  39. }
  40. public static SubdomainRoute MapSubdomainRoute(this AreaRegistrationContext context, string name, string subDomain, string url, object defaults)
  41. {
  42. SubdomainRoute route = new SubdomainRoute(
  43. subDomain,
  44. url,
  45. new RouteValueDictionary(defaults),
  46. new RouteValueDictionary(new {}),
  47. new RouteValueDictionary(new {Area = context.AreaName}),
  48. new MvcRouteHandler());
  49. context.Routes.Add(AddSubToName(subDomain, name), route);
  50. return route;
  51. }
  52. public static SubdomainRoute MapSubdomainRoute(this AreaRegistrationContext context, string name, string subDomain, string url, object defaults, object constraints)
  53. {
  54. SubdomainRoute route = new SubdomainRoute(
  55. subDomain,
  56. url,
  57. new RouteValueDictionary(defaults),
  58. new RouteValueDictionary(constraints),
  59. new RouteValueDictionary(new {Area = context.AreaName}),
  60. new MvcRouteHandler());
  61. context.Routes.Add(AddSubToName(subDomain, name), route);
  62. return route;
  63. }
  64. public static SubdomainRoute MapSubdomainRoute(this AreaRegistrationContext context, string name, string subDomain, string url, object defaults, string[] namespaces)
  65. {
  66. SubdomainRoute route = new SubdomainRoute(
  67. subDomain,
  68. url,
  69. new RouteValueDictionary(defaults),
  70. new RouteValueDictionary(new {}),
  71. new RouteValueDictionary(new { Area = context.AreaName, Namespaces = namespaces }),
  72. new MvcRouteHandler());
  73. context.Routes.Add(AddSubToName(subDomain, name), route);
  74. return route;
  75. }
  76. public static SubdomainRoute MapSubdomainRoute(this AreaRegistrationContext context, string name, string subDomain, string url, string area, object defaults)
  77. {
  78. SubdomainRoute route = new SubdomainRoute(
  79. subDomain,
  80. url,
  81. new RouteValueDictionary(defaults),
  82. new RouteValueDictionary(new { }),
  83. new RouteValueDictionary(new { Area = area }),
  84. new MvcRouteHandler());
  85. context.Routes.Add(AddSubToName(subDomain, name), route);
  86. return route;
  87. }
  88. public static SubdomainRoute MapSubdomainRoute(this AreaRegistrationContext context, string name, string subDomain, string url, string area, object defaults, object constraints)
  89. {
  90. SubdomainRoute route = new SubdomainRoute(
  91. subDomain,
  92. url,
  93. new RouteValueDictionary(defaults),
  94. new RouteValueDictionary(constraints),
  95. new RouteValueDictionary(new { Area = area }),
  96. new MvcRouteHandler());
  97. context.Routes.Add(AddSubToName(subDomain, name), route);
  98. return route;
  99. }
  100. public static SubdomainRoute MapSubdomainRoute(this AreaRegistrationContext context, string name, string subDomain, string url, string area, object defaults, string[] namespaces)
  101. {
  102. SubdomainRoute route = new SubdomainRoute(
  103. subDomain,
  104. url,
  105. new RouteValueDictionary(defaults),
  106. new RouteValueDictionary(new { }),
  107. new RouteValueDictionary(new { Area = area, Namespaces = namespaces }),
  108. new MvcRouteHandler());
  109. context.Routes.Add(AddSubToName(subDomain, name), route);
  110. return route;
  111. }
  112. private static string AddSubToName(string sub, string name)
  113. {
  114. string newName = name;
  115. if (!string.IsNullOrEmpty(sub))
  116. {
  117. newName = sub + "." + name;
  118. }
  119. return newName;
  120. }
  121. }
  122. }