コード例 #1
0
        protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var dataContext = WorkContext.GetDataContext();

            FrontContext.Current = new FrontContext
            {
                DataContext = dataContext
            };

            var parser       = new PageRouteParser(dataContext, requestContext);
            var matchedSites = parser.GetMatchedSites();

            foreach (var matchedSite in matchedSites)
            {
                var site = matchedSite.Site;
                FrontContext.Current.Site            = site;
                FrontContext.Current.Site.MatchedUrl = matchedSite.SiteUrl;

                var page = parser.GetMatchedPage(matchedSite);
                if (page != null)
                {
                    if (site.RedirectToMainUrl)
                    {
                        var mainUrl = site.Urls.First();
                        if (site.MatchedUrl.Name != mainUrl.Name)
                        {
                            var newPageUrl = parser.PageUrl;
                            var subFolder  = site.MatchedUrl.GetSubFolder();
                            if (!String.IsNullOrWhiteSpace(subFolder))
                            {
                                newPageUrl = newPageUrl.Substring(subFolder.Length);
                            }

                            Redirect301(string.Format("{0}://{1}/{2}",
                                                      HttpContext.Current.Request.IsSecureConnection ? "https" : "http",
                                                      mainUrl.Name, newPageUrl));

                            return(base.GetHttpHandler(requestContext));
                        }
                    }

                    FrontContext.Current.Page = page.Page;

                    parser.MergeRouteData(page.RouteValues, requestContext.RouteData.Values);

                    break;
                }
            }

            return(base.GetHttpHandler(requestContext));
        }
コード例 #2
0
        public override void InitHelpers()
        {
            base.InitHelpers();

            var controller = ViewContext.Controller as AdminControllerBase;

            if (controller != null)
            {
                CurrentSite   = controller.CurrentSite;
                CurrentSiteId = controller.CurrentSiteId;
                CurrentUser   = controller.CurrentUser;
                DataContext   = WorkContext.GetDataContext();
            }

            Validation = new ValidationHelper(ViewContext.HttpContext, ViewData.ModelState);
        }