当前位置: 首页>>代码示例>>C#>>正文


C# ControllerContext.GetAreaName方法代码示例

本文整理汇总了C#中ControllerContext.GetAreaName方法的典型用法代码示例。如果您正苦于以下问题:C# ControllerContext.GetAreaName方法的具体用法?C# ControllerContext.GetAreaName怎么用?C# ControllerContext.GetAreaName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ControllerContext的用法示例。


在下文中一共展示了ControllerContext.GetAreaName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetPath

        /// <summary>
        /// 
        /// </summary>
        /// <param name="controllerContext">Current Controller Context</param>
        /// <param name="locationFormats">View location format or master location format</param>
        /// <param name="areaLocationFormats">Area view location format or area master location format</param>
        /// <param name="locationFormatsPropertyName">location format name as return argument in information</param>
        /// <param name="viewName">Target View Name which is be finding</param>
        /// <param name="controllerName">Current Controller Name</param>
        /// <param name="theme">Target Theme Name which is be finding</param>
        /// <param name="cacheKeyPrefix">Prefix for parts of cache key name</param>
        /// <param name="useCache">If using cache</param>
        /// <param name="workType">Current Work Type (PC or mobile)</param>
        /// <param name="searchedLocations">Get the locations have been searched where don't have view pages</param>
        /// <returns>The path of target view</returns>
        protected virtual string GetPath(
            ControllerContext controllerContext, 
            string[] locationFormats, 
            string[] areaLocationFormats, 
            string locationFormatsPropertyName, 
            string viewName, 
            string controllerName, 
            string theme, 
            string cacheKeyPrefix, 
            bool useCache, 
            WorkType workType, 
            out string[] searchedLocations)
        {
            searchedLocations = null; // initialize searched locations

            // if view name is empty, return empty
            if (string.IsNullOrEmpty(viewName))
                return string.Empty;

            // get current area name
            string areaName = controllerContext.GetAreaName();

            // handle admin area
            if (!string.IsNullOrEmpty(areaName) && areaName.Equals("admin", StringComparison.InvariantCultureIgnoreCase))
            {
                // don't support mobile for admin
                if (workType == WorkType.Mobile)
                {
                    searchedLocations = new string[0]; // empty because program doesn't search any location
                    return string.Empty;
                }

                var formats = areaLocationFormats.ToList();
                formats.InsertRange(0, LocationSettings.AdminLocationFormat); // make sure admin location is the default searching location
                areaLocationFormats = formats.ToArray();
            }

            var viewLocations = GetViewLocations(locationFormats, !string.IsNullOrEmpty(areaName) ? areaLocationFormats : null); // pass location format and area location format (if area is not in url, pass null)
            if (viewLocations.Count == 0)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Properties cannot be null or empty.", new object[] { locationFormatsPropertyName }));
            }

            string keyName = this.CreateCacheKey(
                cacheKeyPrefix,
                viewName,
                this.CheckIfRelativePath(viewName) ? string.Empty : controllerName,  // if the view name includes controller name, will not pass controller name
                areaName,
                theme);

            if (useCache)
            {
                // use API to cache view location
                var cachedLocation = this.ViewLocationCache.GetViewLocation(controllerContext.HttpContext, keyName);
                if (null != cachedLocation)
                    return cachedLocation; // if location has been cached, return;
            }

            // if useCache is false and view location hasn't been cached.
            // No matter whether the useCache is true or not, location always inserts into cache
            // the view name doesn't includes path
            if (!this.CheckIfRelativePath(viewName))
            {
                return this.GetPathFromGeneralName(controllerContext, viewLocations, viewName, controllerName, areaName, theme, keyName, ref searchedLocations);
            }
            else
            {
                return this.GetPathFromSpecificName(controllerContext, viewName, keyName, ref searchedLocations);
            }
        }
开发者ID:popunit,项目名称:MyEFramework,代码行数:85,代码来源:ThemeableVirtualPathProviderViewEngine.cs


注:本文中的ControllerContext.GetAreaName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。