internal static void DetermineAreaAndModule <TController>(RouteCollection routes, out string areaName, out string moduleName) where TController : ControllerBase
        {
            areaName = moduleName = null;

            string controllerNamespace = typeof(TController).Namespace;

            if (string.IsNullOrEmpty(controllerNamespace))
            {
                throw new ArgumentException("The controller type is not defines a namespace.");
            }

            foreach (RouteBase route in from r in routes
                     let ns = RouteHelpers.GetMvcNamespaces(r)
                              where ns != null && ns.Contains(controllerNamespace)
                              select r)
            {
                if (!string.IsNullOrEmpty(areaName) && !string.IsNullOrEmpty(moduleName))
                {
                    break;
                }

                if (string.IsNullOrEmpty(areaName))
                {
                    areaName = AreaHelpers.GetAreaName(route);
                }
                if (string.IsNullOrEmpty(moduleName))
                {
                    moduleName = AreaHelpers.GetModuleName(route);
                }
            }
        }
        private string GetPath(ControllerContext controllerContext, string[] locations, string[] areaLocations, string[] moduleLocations, string[] moduleAreaLocations, string locationsPropertyName, string name, string controllerName, string cacheKeyPrefix, bool useCache, out string[] searchedLocations)
        {
            searchedLocations = g_emptyLocations;

            if (String.IsNullOrEmpty(name))
            {
                return(String.Empty);
            }

            string moduleName   = AreaHelpers.GetModuleName(controllerContext.RouteData);
            string areaName     = AreaHelpers.GetAreaName(controllerContext.RouteData);
            bool   usingModules = !string.IsNullOrEmpty(moduleName);
            bool   usingAreas   = !String.IsNullOrEmpty(areaName);
            List <ViewLocation> viewLocations = GetViewLocations(
                locations,
                usingModules || !usingAreas ? null : areaLocations,
                !usingModules ? null : moduleLocations,
                !usingModules || !usingAreas ? null : moduleAreaLocations);

            if (viewLocations.Count == 0)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  "The property '{0}' cannot be null or empty.", locationsPropertyName));
            }

            bool   nameRepresentsPath = IsSpecificPath(name);
            string cacheKey           = this.CreateCacheKey(cacheKeyPrefix, name, (nameRepresentsPath) ? String.Empty : controllerName, areaName, moduleName);

            if (useCache)
            {
                // Only look at cached display modes that can handle the context.
                string cachedLocation = null;
                IEnumerable <IDisplayMode> possibleDisplayModes = DisplayModeProvider.GetAvailableDisplayModesForContext(controllerContext.HttpContext, controllerContext.DisplayMode);
                foreach (IDisplayMode displayMode in possibleDisplayModes)
                {
                    cachedLocation = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, this.AppendDisplayModeToCacheKey(cacheKey, displayMode.DisplayModeId));

                    if (cachedLocation != null)
                    {
                        if (controllerContext.DisplayMode == null)
                        {
                            controllerContext.DisplayMode = displayMode;
                        }
                        break;
                    }
                }

                // if cachedLocation is null GetPath will be called again without using the cache.
                return(cachedLocation);
            }
            else
            {
                return((nameRepresentsPath) ?
                       this.GetPathFromSpecificName(controllerContext, name, cacheKey, ref searchedLocations) :
                       this.GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, moduleName, cacheKey, ref searchedLocations));
            }
        }