1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
15 using System.Collections.Generic;
\r
16 using System.Diagnostics.CodeAnalysis;
\r
18 using System.Web.Routing;
\r
20 public class AreaRegistrationContext {
\r
22 private readonly HashSet<string> _namespaces = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
\r
24 public AreaRegistrationContext(string areaName, RouteCollection routes)
\r
25 : this(areaName, routes, null) {
\r
28 public AreaRegistrationContext(string areaName, RouteCollection routes, object state) {
\r
29 if (String.IsNullOrEmpty(areaName)) {
\r
30 throw Error.ParameterCannotBeNullOrEmpty("areaName");
\r
32 if (routes == null) {
\r
33 throw new ArgumentNullException("routes");
\r
36 AreaName = areaName;
\r
41 public string AreaName {
\r
46 public ICollection<string> Namespaces {
\r
52 public RouteCollection Routes {
\r
57 public object State {
\r
62 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",
\r
63 Justification = "This is not a regular URL as it may contain special routing characters.")]
\r
64 public Route MapRoute(string name, string url) {
\r
65 return MapRoute(name, url, (object)null /* defaults */);
\r
68 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",
\r
69 Justification = "This is not a regular URL as it may contain special routing characters.")]
\r
70 public Route MapRoute(string name, string url, object defaults) {
\r
71 return MapRoute(name, url, defaults, (object)null /* constraints */);
\r
74 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",
\r
75 Justification = "This is not a regular URL as it may contain special routing characters.")]
\r
76 public Route MapRoute(string name, string url, object defaults, object constraints) {
\r
77 return MapRoute(name, url, defaults, constraints, null /* namespaces */);
\r
80 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",
\r
81 Justification = "This is not a regular URL as it may contain special routing characters.")]
\r
82 public Route MapRoute(string name, string url, string[] namespaces) {
\r
83 return MapRoute(name, url, (object)null /* defaults */, namespaces);
\r
86 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",
\r
87 Justification = "This is not a regular URL as it may contain special routing characters.")]
\r
88 public Route MapRoute(string name, string url, object defaults, string[] namespaces) {
\r
89 return MapRoute(name, url, defaults, null /* constraints */, namespaces);
\r
92 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#",
\r
93 Justification = "This is not a regular URL as it may contain special routing characters.")]
\r
94 public Route MapRoute(string name, string url, object defaults, object constraints, string[] namespaces) {
\r
95 if (namespaces == null && Namespaces != null) {
\r
96 namespaces = Namespaces.ToArray();
\r
99 Route route = Routes.MapRoute(name, url, defaults, constraints, namespaces);
\r
100 route.DataTokens["area"] = AreaName;
\r
102 // disabling the namespace lookup fallback mechanism keeps this areas from accidentally picking up
\r
103 // controllers belonging to other areas
\r
104 bool useNamespaceFallback = (namespaces == null || namespaces.Length == 0);
\r
105 route.DataTokens["UseNamespaceFallback"] = useNamespaceFallback;
\r