コード例 #1
0
        public void SaveUseMainLayout(long mediaDetailId, string html)
        {
            var mediaDetail = (MediaDetail)MediaDetailsMapper.GetByID(mediaDetailId);

            if (mediaDetail != null)
            {
                if (mediaDetail.UseMediaTypeLayouts)
                {
                    mediaDetail.MediaType.MainLayout = Uri.UnescapeDataString(html);
                }
                else
                {
                    mediaDetail.MainLayout = Uri.UnescapeDataString(html);
                }

                var returnObj = MediaDetailsMapper.Update(mediaDetail);

                WriteJSON(returnObj.ToJson());
            }
            else
            {
                WriteJSON(new Return()
                {
                    Error = new Elmah.Error()
                    {
                        Message = $"MediaDetail with the ID '{mediaDetailId}' was not found"
                    }
                }.ToJson());
            }
        }
コード例 #2
0
        public void ClearCache(long id)
        {
            var detail = MediaDetailsMapper.GetByID(id);

            UserMustHaveAccessTo(detail);
            detail.RemoveFromCache();
        }
コード例 #3
0
        protected void ClassTypesDropDownList_TextChanged(object sender, EventArgs e)
        {
            if (ClassTypesDropDownList.SelectedItem == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(ClassTypesDropDownList.SelectedItem.Value))
            {
                return;
            }

            var classType = MediaDetailsMapper.GetByID(long.Parse(ClassTypesDropDownList.SelectedItem.Value));

            var cmd = "_xclick";

            if (!string.IsNullOrEmpty(classType.RecurringTimePeriod))
            {
                cmd = "_xclick-subscriptions&src=1&t3=" + classType.RecurringTimePeriod + "&a3=" + classType.Price + "&p3=1";
            }

            var taxAmount = ((decimal.Parse(ClassTypesDropDownList.SelectedItem.Value) * FrameworkLibrary.SettingsMapper.GetSettings().ShoppingCartTax) / 100).ToString("0.00");

            BuyNowButton.NavigateUrl = "https://www.paypal.com/cgi-bin/webscr?button=buynow&business=" + AppSettings.PayPalBuisnessID + "&item_name=" + ClassTypesDropDownList.SelectedItem.Text + "&quantity=1&amount=" + classType.Price + "&currency_code=CAD&shipping=0&tax=" + taxAmount + "&cmd=" + cmd + "&bn=JavaScriptButton_buynow&env=www";
            BuyNowButton.Visible     = true;
        }
コード例 #4
0
        public void UnDelete(long id)
        {
            var detail = MediaDetailsMapper.GetByID(id);

            UserMustHaveAccessTo(detail);
            SetDeleteStatus(detail, false);
        }
コード例 #5
0
        public void HideFromMenu(long id)
        {
            var detail = MediaDetailsMapper.GetByID(id);

            UserMustHaveAccessTo(detail);

            SetShowInMenuStatus((MediaDetail)detail, false);
        }
コード例 #6
0
        public void MoveDown(long id)
        {
            var detail = MediaDetailsMapper.GetByID(id);

            UserMustHaveAccessTo(detail);

            detail.Media.MoveDown();
        }
コード例 #7
0
        public void GetFieldsByID(long id)
        {
            string json = "";

            IMediaDetail detail = MediaDetailsMapper.GetByID(id);


            WriteJSON(json);
        }
コード例 #8
0
        public void RenderField(long mediaDetailId, string fieldCode)
        {
            var mediaDetail = MediaDetailsMapper.GetByID(mediaDetailId);

            if (mediaDetail != null)
            {
                var html = mediaDetail.RenderField(fieldCode, true);
                WriteHtml(html);
            }
        }
コード例 #9
0
        public void CopyProperties(IMediaDetail toItem, IMediaDetail fromItem)
        {
            foreach (var field in fromItem.Fields)
            {
                var newField = new MediaDetailField();

                var foundField = toItem.Fields.FirstOrDefault(i => i.FieldCode == field.FieldCode);

                if (foundField != null)
                {
                    newField = foundField;
                }

                newField.CopyFrom(field);

                foreach (var fieldAssociation in field.FieldAssociations)
                {
                    var newFieldAssociation = new FieldAssociation();
                    newFieldAssociation.CopyFrom(fieldAssociation);

                    var associatedMediaDetail = (MediaDetail)MediaDetailsMapper.GetByID(newFieldAssociation.AssociatedMediaDetailID);

                    if (associatedMediaDetail == null)
                    {
                        continue;
                    }

                    if (!associatedMediaDetail.MediaType.ShowInSiteTree)
                    {
                        newFieldAssociation.MediaDetail = (MediaDetail)MediaDetailsMapper.CreateObject(associatedMediaDetail.MediaType.ID, MediasMapper.CreateObject(), associatedMediaDetail.Media.ParentMedia);
                        newFieldAssociation.MediaDetail.CopyFrom(associatedMediaDetail);
                        newFieldAssociation.MediaDetail.DateCreated   = newFieldAssociation.MediaDetail.DateLastModified = DateTime.Now;
                        newFieldAssociation.MediaDetail.CreatedByUser = newFieldAssociation.MediaDetail.LastUpdatedByUser = FrameworkSettings.CurrentUser;

                        CopyProperties(newFieldAssociation.MediaDetail, associatedMediaDetail);
                    }

                    /*if (newFieldAssociation.MediaDetail != null)
                     * {
                     *  newFieldAssociation.MediaDetail.HistoryForMediaDetailID = fieldAssociation.AssociatedMediaDetailID;
                     *  newFieldAssociation.MediaDetail.HistoryVersionNumber = newFieldAssociation.MediaDetail.HistoryVersionNumber + 1;
                     * }*/


                    newField.FieldAssociations.Add(newFieldAssociation);
                }

                if (newField.ID == 0)
                {
                    toItem.Fields.Add(newField);
                }
            }
        }
コード例 #10
0
        public void ClearCache(long id)
        {
            if (id != 0)
            {
                var item = MediaDetailsMapper.GetByID(id);

                if (item != null)
                {
                    item.RemoveFromCache();
                }
            }
        }
コード例 #11
0
        public void GetRelatedItemsByID(long id)
        {
            string json = "";
            IEnumerable <IMediaDetail> relatedItems = new List <IMediaDetail>();
            IMediaDetail detail = MediaDetailsMapper.GetByID(id);

            if (detail != null)
            {
                relatedItems = MediaDetailsMapper.GetRelatedItems(detail);
            }

            WriteJSON(relatedItems.ToJson());
        }
コード例 #12
0
        public void GetByID(long id)
        {
            string json = "";

            IMediaDetail detail = MediaDetailsMapper.GetByID(id);

            if (detail != null)
            {
                json = detail.ToJson();
            }

            WriteJSON(json);
        }
コード例 #13
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            var commandArgument = ((LinkButton)sender).CommandArgument;

            if (!string.IsNullOrEmpty(commandArgument))
            {
                var item = MediaDetailsMapper.GetByID(long.Parse(commandArgument));

                if (item != null)
                {
                    HandleDeleteAssociation(item.Media);
                }
            }
        }
コード例 #14
0
        public void CreateChild(long id)
        {
            if (!FrameworkSettings.CurrentUser.HasPermission(PermissionsEnum.Save))
            {
                throw new Exception("You do not have the appropriate permissions to create items");
            }

            var detail = MediaDetailsMapper.GetByID(id);

            UserMustHaveAccessTo(detail);

            AdminBasePage.SelectedMediaDetail = detail;
            AdminBasePage.SelectedMedia       = detail.Media;
        }
コード例 #15
0
        public void GetFilterOptions(long id)
        {
            string json = "";

            IEnumerable <string> filterOptions = new List <string>();
            IMediaDetail         detail        = MediaDetailsMapper.GetByID(id);

            if (detail != null)
            {
                filterOptions = MediaDetailsMapper.GetFilterOptions(detail);
            }

            WriteJSON(filterOptions.ToJson());
        }
コード例 #16
0
        public void DeletePermanently(long id)
        {
            var detail = MediaDetailsMapper.GetByID(id);

            if (detail != null)
            {
                UserMustHaveAccessTo(detail);

                detail.RemoveFromCache();

                HandleDeletePermanentlyRecursive(detail.Media);
                ContextHelper.ClearAllMemoryCache();
            }
        }
コード例 #17
0
        public void SaveUseMainLayout(long mediaDetailId, string html)
        {
            if (FrameworkSettings.CurrentUser == null)
            {
                var returnObj = BaseMapper.GenerateReturn("You must be logged in");
                WriteJSON(returnObj.ToJson());
                return;
            }

            var mediaDetail = (MediaDetail)MediaDetailsMapper.GetByID(mediaDetailId);

            var history = (MediaDetail)MediaDetailsMapper.CreateHistory(mediaDetail, false);

            mediaDetail.History.Add(history);

            if (!FrameworkSettings.CurrentUser.HasPermission(PermissionsEnum.Save))
            {
                var returnObj = BaseMapper.GenerateReturn("You do not have permissions to perform this operation");
                WriteJSON(returnObj.ToJson());
                return;
            }

            if (mediaDetail != null)
            {
                mediaDetail.UseMediaTypeLayouts = false;

                html = Uri.UnescapeDataString(html);
                //html = MediaDetailsMapper.ConvertUrlsToShortCodes(html);

                html = html.Replace(URIHelper.BaseUrl, "{BaseUrl}");

                mediaDetail.MainLayout = html;

                var returnObj = MediaDetailsMapper.Update(mediaDetail);

                WriteJSON(returnObj.ToJson());
            }
            else
            {
                WriteJSON(new Return()
                {
                    Error = new Elmah.Error()
                    {
                        Message = $"MediaDetail with the ID '{mediaDetailId}' was not found"
                    }
                }.ToJson());
            }
        }
コード例 #18
0
        protected void Edit_Click(object sender, EventArgs e)
        {
            var id = ((LinkButton)sender).CommandArgument;

            if (id != "")
            {
                var mediaDetail = MediaDetailsMapper.GetByID(long.Parse(id));

                if (mediaDetail != null)
                {
                    var url = AdminBasePage.GetAdminUrl(mediaDetail.MediaTypeID, mediaDetail.MediaID);

                    Response.Redirect(url);
                }
            }
        }
コード例 #19
0
        public void CanAccessFrontEndEditorForMediaDetail(long id)
        {
            var returnObj   = new Return();
            var mediaDetail = MediaDetailsMapper.GetByID(id);

            if (mediaDetail != null && FrameworkSettings.CurrentUser != null)
            {
                returnObj = MediaDetailsMapper.CanAccessMediaDetail(mediaDetail, FrameworkSettings.CurrentUser);
                WriteJSON(StringHelper.ObjectToJson(returnObj));
            }

            returnObj = new Return()
            {
                Error = new Elmah.Error(new Exception("Cannot access"))
            };
            WriteJSON(StringHelper.ObjectToJson(returnObj));
        }
コード例 #20
0
        public string Duplicate(long id, bool duplicateChildren = false, string newName = "")
        {
            var detail = MediaDetailsMapper.GetByID(id);

            if (detail != null)
            {
                UserMustHaveAccessTo(detail);

                var mediaDetail = HandleDuplicate(detail, detail.Media.ParentMedia, duplicateChildren, newName, false);

                ContextHelper.ClearAllMemoryCache();

                var url = WebApplication.BasePage.GetAdminUrl(mediaDetail.MediaTypeID, mediaDetail.MediaID);
                return(url);
            }

            return("");
        }
コード例 #21
0
        protected void Edit_Click(object sender, System.EventArgs e)
        {
            var commandArgument = ((LinkButton)sender).CommandArgument;

            if (string.IsNullOrEmpty(commandArgument))
            {
                return;
            }

            var item = MediaDetailsMapper.GetByID(long.Parse(commandArgument));

            if (item == null)
            {
                return;
            }

            WebApplication.BasePage.RedirectToAdminUrl(item);
        }
コード例 #22
0
        private void SaveToDB(string value)
        {
            var obj = StringHelper.JsonToObject <List <JsonObj> >(value);

            if (obj == null)
            {
                return;
            }

            var field = GetField();

            var newIds = StringHelper.ObjectToJson(obj.Select(i => i.id).ToList());
            var oldIds = StringHelper.ObjectToJson(field.FieldAssociations.Select(i => i.AssociatedMediaDetailID).ToList());

            if (newIds == oldIds)
            {
                return;
            }

            var fieldAssociations = field.FieldAssociations.ToList();

            foreach (var item in fieldAssociations)
            {
                BaseMapper.DeleteObjectFromContext(item);
            }

            var orderIndex = 0;

            foreach (var item in obj)
            {
                var mediaDetail = (MediaDetail)MediaDetailsMapper.GetByID(item.id);

                if (mediaDetail != null)
                {
                    field.FieldAssociations.Add(new FieldAssociation()
                    {
                        MediaDetail = mediaDetail, MediaDetailField = field, OrderIndex = orderIndex
                    });
                    orderIndex++;
                }
            }

            var returnObj = BaseMapper.GetDataModel().SaveChanges();
        }
コード例 #23
0
        public string UnPublish(long id)
        {
            var detail = MediaDetailsMapper.GetByID(id);

            UserMustHaveAccessTo(detail);

            var returnObj = SetPublishStatus((MediaDetail)detail, false);

            if (returnObj.IsError)
            {
                return(returnObj.Error.Message);
            }
            else
            {
                if (returnObj.HasInfoMessage)
                {
                    return(returnObj.InfoMessage);
                }
                return("");
            }
        }
コード例 #24
0
        protected void Page_Init(object sender, EventArgs e)
        {
            var mediaDetailIdStr = Request["mediaDetailId"];

            if (!string.IsNullOrEmpty(mediaDetailIdStr))
            {
                long mediaDetailId = 0;
                long.TryParse(mediaDetailIdStr, out mediaDetailId);

                var mediaDetail = MediaDetailsMapper.GetByID(mediaDetailId);

                if (mediaDetail != null)
                {
                    /*if(mediaDetail.UseMediaTypeLayouts)
                     * {
                     *  MediaTypeFieldsEditorWrapper.Visible = true;
                     *  MediaTypeFieldsEditor.SetItems(mediaDetail.MediaType);
                     * }
                     * else
                     * {*/
                    MediaDetailFieldsEditorWrapper.Visible = true;
                    FieldsTab.SetObject(mediaDetail);
                    //}
                }
                else
                {
                    MediaDetailFieldsEditorWrapper.Visible = false;
                    MediaDetailFieldsEditorWrapper.Visible = false;
                }
            }
            else
            {
                MediaDetailFieldsEditorWrapper.Visible = false;
                MediaDetailFieldsEditorWrapper.Visible = false;
            }

            BindGlobalFields();
        }
コード例 #25
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            var id = ((LinkButton)sender).CommandArgument;

            if (id != "")
            {
                var mediaDetail = MediaDetailsMapper.GetByID(long.Parse(id));

                if (mediaDetail != null)
                {
                    var returnObj = MediaDetailsMapper.DeletePermanently((MediaDetail)mediaDetail);

                    if (returnObj.IsError)
                    {
                        BasePage.DisplayErrorMessage("Error", returnObj.Error);
                    }
                    else
                    {
                        BasePage.DisplaySuccessMessage("Successfully deleted item");
                    }
                }
            }
        }
コード例 #26
0
        protected void RemoveFromCart_OnClick(object sender, EventArgs e)
        {
            LinkButton senderItem = (LinkButton)sender;

            CurrentCart.RemoveItem(MediaDetailsMapper.GetByID(long.Parse(senderItem.CommandArgument)));
        }
コード例 #27
0
        public IMediaDetail HandleDuplicate(IMediaDetail detail, Media parentMedia, bool duplicateChildren = false, string newName = "", bool autoPublish = true)
        {
            var duplicatedItem = MediaDetailsMapper.CreateObject(detail.MediaTypeID, null, parentMedia, false);

            duplicatedItem.CopyFrom(detail, new List <string> {
                "MediaID", "Media"
            });

            if (newName != "")
            {
                duplicatedItem.Title = duplicatedItem.LinkTitle = newName;
            }

            duplicatedItem.CachedVirtualPath = duplicatedItem.CalculatedVirtualPath();

            /*if (duplicatedItem.ID == 0)
             * {
             *  var mediaType = MediaTypesMapper.GetByID(detail.MediaTypeID);
             *  var createdItems = mediaType.MediaDetails.Where(i => !i.IsHistory && i.ParentMediaID == detail.ParentMediaID && i.LanguageID == detail.LanguageID).Select(i => i);
             *
             *  var newIndex = createdItems.Count() + 1;
             *
             *  duplicatedItem.LinkTitle = detail.Language.DisplayName + " - " + mediaType.Name + " " + newIndex;
             * }*/

            duplicatedItem.Media.OrderIndex = parentMedia.ChildMedias.Count(i => i.ID != 0);

            duplicatedItem.PublishDate = duplicatedItem.DateCreated = duplicatedItem.DateLastModified = DateTime.Now;

            //var fields = detail.Fields.ToList();

            foreach (var item in detail.Fields)
            {
                var mediaDetailField = new MediaDetailField();
                mediaDetailField.CopyFrom(item);

                if (newName != "" && mediaDetailField.FieldCode == "SectionTitle")
                {
                    mediaDetailField.FieldValue = newName;
                }

                mediaDetailField.DateCreated = mediaDetailField.DateLastModified = DateTime.Now;

                foreach (var association in item.FieldAssociations)
                {
                    var fieldAssociation = new FieldAssociation();
                    fieldAssociation.CopyFrom(association);

                    if (item.AdminControl.Contains("MultiFile"))
                    {
                        var associatedMediaDetail = MediaDetailsMapper.GetByID(fieldAssociation.AssociatedMediaDetailID);
                        fieldAssociation.AssociatedMediaDetailID = 0;

                        fieldAssociation.MediaDetail = (MediaDetail)HandleDuplicate(associatedMediaDetail, associatedMediaDetail.Media.ParentMedia, true);
                    }

                    mediaDetailField.FieldAssociations.Add(fieldAssociation);
                }

                duplicatedItem.Fields.Add(mediaDetailField);
            }

            if (!autoPublish)
            {
                duplicatedItem.PublishDate = null;
            }

            var returnObj = MediaDetailsMapper.Insert(duplicatedItem);

            if (returnObj.IsError)
            {
                throw returnObj.Error.Exception;
            }
            else
            {
                if (duplicateChildren)
                {
                    var childMediaDetails = detail.ChildMediaDetails;
                    foreach (var childDetail in childMediaDetails)
                    {
                        HandleDuplicate(childDetail, duplicatedItem.Media);
                    }

                    /*foreach (var child in detail.Media.ChildMedias)
                     * {
                     *  var mediaDetailsToCopy = child.MediaDetails.Where(i => !i.IsDraft && !i.IsHistory);
                     *
                     *  foreach (var childDetail in mediaDetailsToCopy)
                     *  {
                     *      HandleDuplicate(childDetail, duplicatedItem.Media);
                     *  }
                     * }*/
                }
            }

            return(duplicatedItem);
        }
コード例 #28
0
        private void UpdatedObjectFromFields(MediaDetailField mediaField)
        {
            mediaField.MediaDetailID                = mediaDetail.ID;
            mediaField.FieldCode                    = FieldCode.Text;
            mediaField.FieldLabel                   = FieldLabel.Text;
            mediaField.AdminControl                 = AdminControl.Text;
            mediaField.FieldValue                   = ParserHelper.ParseData(FieldValue.Text, BasePage.TemplateVars, true);
            mediaField.GroupName                    = GroupName.Text;
            mediaField.RenderLabelAfterControl      = RenderLabelAfterControl.Checked;
            mediaField.GetAdminControlValue         = GetAdminControlValue.Text;
            mediaField.SetAdminControlValue         = SetAdminControlValue.Text;
            mediaField.FrontEndLayout               = FrontEndLayout.Text;
            mediaField.FieldDescription             = FieldDescription.GetValue().ToString();
            mediaField.UseMediaTypeFieldDescription = UseMediaTypeFieldDescription.Checked;
            mediaField.ShowFrontEndFieldEditor      = ShowFrontEndFieldEditor.Checked;
            mediaField.IsGlobalField                = IsGlobalField.Checked;

            if (string.IsNullOrEmpty(UsageExample.Text))
            {
                if (mediaField.MediaDetail == null && mediaField.MediaDetailID != 0)
                {
                    mediaField.MediaDetail = (MediaDetail)MediaDetailsMapper.GetByID(mediaField.MediaDetailID);
                }

                if (mediaField.MediaDetail != null)
                {
                    UsageExample.Text = "{Field:" + mediaField.FieldCode + "} OR {{Load:" + mediaField.MediaDetail.MediaID + "}.Field:" + mediaField.FieldCode + "}";
                }
            }

            mediaField.UsageExample = UsageExample.Text;


            if (mediaField.FieldSettings == null)
            {
                mediaField.FieldSettings = "";
            }

            if (mediaField.FrontEndSubmissions == null)
            {
                mediaField.FrontEndSubmissions = "";
            }


            var mediaTypeField = mediaDetail.MediaType.Fields.SingleOrDefault(i => i.FieldCode == mediaField.FieldCode);

            if (mediaTypeField != null)
            {
                mediaField.UseMediaTypeFieldFrontEndLayout = UseMediaTypeFieldFrontEndLayout.Checked;

                if (AssociateWithMediaTypeField.Checked)
                {
                    mediaField.MediaTypeField = mediaTypeField;
                }
                else
                {
                    mediaField.MediaTypeField = null;
                }
            }
            else
            {
                mediaField.UseMediaTypeFieldFrontEndLayout = false;
            }

            mediaField.DateCreated      = DateTime.Now;
            mediaField.DateLastModified = DateTime.Now;

            //BindVisibility(mediaField);
        }
コード例 #29
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            RedisCacheHelper.SetRedisCacheConnectionString(AppSettings.RedisCacheConnectionString);
            FileCacheHelper.SetFileSystemCacheDirPath(AppSettings.FileSystemCacheDirPath);

            virtualPath = URIHelper.GetCurrentVirtualPath().ToLower();

            var queryString = HttpContext.Current.Request.QueryString.ToString();

            queryString = System.Web.HttpUtility.UrlDecode(queryString);


            if (!Request.Path.EndsWith("/") || ((virtualPath != "~/") && (!virtualPath.EndsWith("/"))))
            {
                var path = Request.Path + "/";

                if (!string.IsNullOrEmpty(queryString))
                {
                    path = path + "?" + queryString;
                }

                HttpContext.Current.Response.RedirectPermanent(path);
            }

            Settings cmsSettings            = null;
            bool     isAttemptingAdminLogin = false;

            if ((virtualPath != "~/login/") && (virtualPath != "~/admin/") && string.IsNullOrEmpty(Request.QueryString["format"]))
            {
                cmsSettings = SettingsMapper.GetSettings();

                if (cmsSettings != null)
                {
                    var isSiteOnline = cmsSettings.IsSiteOnline();

                    if (isSiteOnline)
                    {
                        if (virtualPath.Contains(cmsSettings.SiteOfflineUrl))
                        {
                            Response.Redirect("~/");
                        }

                        AttemptToLoadFromCache();
                    }
                    else
                    {
                        if (!virtualPath.Contains(cmsSettings.SiteOfflineUrl))
                        {
                            Response.Redirect(cmsSettings.SiteOfflineUrl);
                        }
                    }
                }
                else
                {
                    AttemptToLoadFromCache();
                }
            }
            else
            {
                isAttemptingAdminLogin = true;
            }

            var languageSegment = FrameworkSettings.GetCurrentLanguage().UriSegment;

            if (LanguagesMapper.GetAllActive().Count() > 1 && !Request.Url.PathAndQuery.Contains($"/{languageSegment}/"))
            {
                var url = URIHelper.ConvertToAbsUrl("/" + languageSegment + Request.Url.PathAndQuery);
                Response.RedirectPermanent(url, true);
            }

            var segments = URIHelper.GetUriSegments(virtualPath).ToList();

            string firstSegment = "";

            if (segments.Count > 0)
            {
                firstSegment = segments[0];

                var language = LanguagesMapper.GetAllActive().SingleOrDefault(i => i.UriSegment == firstSegment);

                if (language != null)
                {
                    FrameworkSettings.SetCurrentLanguage(language);
                }
            }

            if (!isAttemptingAdminLogin && AppSettings.EnableUrlRedirectRules)
            {
                var path = virtualPath;

                if (!string.IsNullOrEmpty(queryString))
                {
                    path = path + "?" + queryString;
                }

                var redirectRule = UrlRedirectRulesMapper.GetRuleForUrl(path);

                if (redirectRule != null)
                {
                    var newUrl = redirectRule.RedirectToUrl;

                    if (newUrl.Contains("{"))
                    {
                        newUrl = MediaDetailsMapper.ParseSpecialTags(redirectRule, newUrl);
                    }

                    newUrl = URIHelper.ConvertToAbsUrl(newUrl);

                    var possibleLoopRules      = UrlRedirectRulesMapper.GetRulesFromUrl(URIHelper.ConvertAbsUrlToTilda(newUrl));
                    var foundActiveVirtualPath = MediaDetailsMapper.GetByVirtualPath(path);

                    if (possibleLoopRules.Any())
                    {
                        foreach (var rule in possibleLoopRules)
                        {
                            var returnObj = MediaDetailsMapper.DeletePermanently(rule);
                        }
                    }

                    if (foundActiveVirtualPath != null)
                    {
                        var returnObj = MediaDetailsMapper.DeletePermanently(redirectRule);
                    }

                    if (Request.QueryString.Count > 0)
                    {
                        newUrl += "?" + Request.QueryString;
                    }

                    if (redirectRule.Is301Redirect)
                    {
                        Response.RedirectPermanent(newUrl);
                    }
                    else
                    {
                        Response.Redirect(newUrl);
                    }
                }
            }

            if (!File.Exists(HttpContext.Current.Server.MapPath(virtualPath)) && !virtualPath.Contains(ParserHelper.OpenToken) && !virtualPath.Contains(ParserHelper.CloseToken))
            {
                string viewPath = "";

                long mediaDetailId = 0;
                long.TryParse(requestContext.HttpContext.Request["MediaDetailID"], out mediaDetailId);

                long mediaId = 0;
                long.TryParse(requestContext.HttpContext.Request["MediaID"], out mediaId);

                MediaDetail detail = null;

                if (mediaDetailId == 0 && mediaId == 0)
                {
                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByVirtualPath(virtualPath, true);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }
                else if (mediaDetailId != 0)
                {
                    var mediaDetail = MediaDetailsMapper.GetByID(mediaDetailId);

                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMediaDetail(mediaDetail);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }
                else if (mediaId != 0)
                {
                    var media = MediasMapper.GetByID(mediaId);

                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMedia(media);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }

                /*if (detail != null && !detail.CanUserAccessSection(FrameworkSettings.CurrentUser))
                 * {
                 *  FormsAuthentication.RedirectToLoginPage();
                 * }*/

                /*if (detail != null)
                 * {
                 *  var absUrlBase = URIHelper.ConvertAbsUrlToTilda(detail.AbsoluteUrl).Replace("~", "");
                 *  var absPathBase = URIHelper.ConvertAbsUrlToTilda(Request.Url.AbsolutePath).Replace("~", "");
                 *
                 *  if (absUrlBase != absPathBase)
                 *  {
                 *      Response.Redirect(detail.AbsoluteUrl + Request.Url.Query);
                 *  }
                 * }*/

                if (detail != null)
                {
                    if (detail.ForceSSL || AppSettings.ForceSSL)
                    {
                        URIHelper.ForceSSL();
                    }
                }
                else
                {
                    var currentLanguageId = FrameworkSettings.GetCurrentLanguage().ID;

                    var historyVersion = BaseMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.LanguageID == currentLanguageId && i.CachedVirtualPath == virtualPath && i.MediaType.ShowInSiteTree && i.HistoryVersionNumber != 0 && i.HistoryForMediaDetail != null);

                    if (historyVersion != null && historyVersion.VirtualPath != historyVersion.HistoryForMediaDetail.VirtualPath)
                    {
                        var foundRedirectUrl = UrlRedirectRulesMapper.GetRuleForUrl(virtualPath);

                        if (foundRedirectUrl == null)
                        {
                            var urlRedirectRule = UrlRedirectRulesMapper.CreateUrlRedirect(virtualPath, historyVersion.HistoryForMediaDetail.Media);

                            if (urlRedirectRule != null)
                            {
                                var returnObj = UrlRedirectRulesMapper.Insert(urlRedirectRule);
                                HttpContext.Current.Response.RedirectPermanent(historyVersion.HistoryForMediaDetail.CachedVirtualPath);
                            }
                            else
                            {
                                HttpContext.Current.Response.RedirectPermanent("/");
                            }
                        }
                    }
                    else
                    {
                        HttpContext.Current.Response.RedirectPermanent("/");
                    }
                }

                if ((detail == null) || (!IsValidRequest(detail)))
                {
                    detail = null;
                    if (cmsSettings != null)
                    {
                        if (!string.IsNullOrEmpty(cmsSettings.PageNotFoundUrl))
                        {
                            ErrorHelper.LogException(new Exception($"Page Not Found: {virtualPath}"));

                            Response.Redirect(cmsSettings.PageNotFoundUrl);

                            /*FrameworkSettings.CurrentFrameworkBaseMedia = null;
                             *
                             * FrameworkSettings.CurrentFrameworkBaseMedia = FrameworkBaseMedia.GetInstanceByVirtualPath(cmsSettings.PageNotFoundUrl, true);
                             * detail = (MediaDetail)FrameworkSettings.CurrentFrameworkBaseMedia.CurrentMediaDetail;
                             *
                             * ErrorHelper.LogException(new Exception($"Page Not Found: {virtualPath}"));*/

                            //Response.StatusCode = 301;
                        }
                    }
                }

                if (detail != null)
                {
                    var draft = detail.GetLatestDraft();

                    if (draft != null && (draft.PublishDate - detail.PublishDate) > TimeSpan.FromSeconds(10) && draft.CanRender)
                    {
                        var returnObj = draft.PublishLive();

                        if (!returnObj.IsError)
                        {
                            detail.RemoveFromCache();
                            draft.RemoveFromCache();

                            FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMediaDetail(draft);
                            detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                        }
                    }

                    if (detail.RedirectToFirstChild)
                    {
                        var child = detail.ChildMediaDetails.FirstOrDefault();

                        if (child != null)
                        {
                            var redirectPath = child.AutoCalculatedVirtualPath;

                            if (!string.IsNullOrEmpty(queryString))
                            {
                                redirectPath = redirectPath + "?" + queryString;
                            }

                            HttpContext.Current.Response.Redirect(redirectPath);
                        }
                    }

                    viewPath = FrameworkSettings.Current.CurrentMediaDetail.Handler;

                    if ((viewPath == null) || (viewPath.Trim() == ""))
                    {
                        viewPath = MediaTypesMapper.GetByID(FrameworkSettings.Current.CurrentMediaDetail.MediaTypeID).MediaTypeHandler;
                    }

                    viewPath = URIHelper.ConvertAbsUrlToTilda(viewPath);

                    if (!string.IsNullOrEmpty(Request.QueryString["format"]))
                    {
                        FrontEndBasePage.HandleFormatQueryString(detail, Request.QueryString["format"], Request.QueryString["depth"]);
                    }

                    return(CreateInstanceFromVirtualPath(viewPath, typeof(BasePage)));
                }
            }

            return(new DefaultHttpHandler());
        }