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


C# RouteData.ApplyCurrentContent方法代码示例

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


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

示例1: GetRouteData

        /// <summary>
        /// Returns information about the requested route.
        /// </summary>
        /// <param name="httpContext">An object that encapsulates information about the HTTP request.</param>
        /// <returns>
        /// An object that contains the values from the route definition.
        /// </returns>
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            // get the virtual path of the request
            var virtualPath = httpContext.Request.CurrentExecutionFilePath;

            var routeData = new RouteData(this, _routeHandler);

            foreach (var defaultPair in this._defaults)
                routeData.Values[defaultPair.Key] = defaultPair.Value;

            // try to resolve the current item
            var pathData = PathResolver.ResolvePath(routeData, virtualPath.Replace("/ui/pages", string.Empty));

            // Abort and proceed to other routes in the route table
            if (pathData == null) {
                return null;
            }

            routeData.ApplyCurrentPage(DefaultControllerName, pathData.Action, pathData.CurrentPage);
            routeData.ApplyCurrentContent(pathData.CurrentContent);
            routeData.ApplyCurrentStructureInfo(new StructureInfo
            {
                NavigationContext = pathData.NavigationContext.OrderBy(x => x.Metadata.SortOrder),
                CurrentPage = pathData.CurrentPage,
                CurrentContent = pathData.CurrentContent,
                StartPage = pathData.NavigationContext.Single(x => x.Parent == null),
                ParentPage = pathData.CurrentPage.Parent != null ? pathData.NavigationContext.SingleOrDefault(x => x.Id == pathData.CurrentPage.Parent.Id) : null
            });
            return routeData;
        }
开发者ID:bbqchickenrobot,项目名称:brickpile,代码行数:37,代码来源:UIRoute.cs

示例2: GetRouteData

        /// <summary>
        /// Gets the route data.
        /// </summary>
        /// <param name="httpContextBase">The HTTP context base.</param>
        /// <returns></returns>
        public override RouteData GetRouteData(HttpContextBase httpContextBase)
        {
            var routeData = new RouteData(this, _routeHandler);

            // get the virtual path of the request
            var virtualPath = httpContextBase.Request.CurrentExecutionFilePath.TrimStart(new[] { '/' });

            // try to resolve the current item
            var pathData = this.PathResolver.ResolvePath(routeData, virtualPath);

            // Abort and proceed to other routes in the route table
            if (pathData == null) {
                return null;
            }

            // throw a proper 404 if the page is not published or if it's deleted
            if((!pathData.CurrentPage.Metadata.IsPublished || pathData.CurrentPage.Metadata.IsDeleted) && !httpContextBase.User.Identity.IsAuthenticated ) {
                throw new HttpException(404, "HTTP/1.1 404 Not Found");
            }

            routeData.ApplyCurrentPage(pathData.Controller, pathData.Action, pathData.CurrentPage);
            routeData.ApplyCurrentContent(pathData.CurrentContent);
            routeData.ApplyCurrentStructureInfo(new StructureInfo
            {
                NavigationContext = httpContextBase.User.Identity.IsAuthenticated ? pathData.NavigationContext.Where(x => !x.Metadata.IsDeleted).OrderBy(x => x.Metadata.SortOrder) : pathData.NavigationContext.Where(x => x.Metadata.IsPublished).Where(x => !x.Metadata.IsDeleted).OrderBy(x => x.Metadata.SortOrder),
                CurrentPage = pathData.CurrentPage,
                CurrentContent = pathData.CurrentContent,
                StartPage = pathData.NavigationContext.Single(x => x.Parent == null),
                ParentPage = pathData.CurrentPage.Parent != null ? pathData.NavigationContext.SingleOrDefault(x => x.Id == pathData.CurrentPage.Parent.Id) : null
            });

            return routeData;
        }
开发者ID:bbqchickenrobot,项目名称:brickpile,代码行数:38,代码来源:PageRoute.cs


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