protected void Deploy_Click(object sender, EventArgs e) { try { var remoteConnectionStringSetting = FrameworkBaseMedia.PrepareConnectionSettings(WebConfigurationManager.ConnectionStrings[DeployToEnvironment.SelectedValue]); //var localConnectionStringSetting = FrameworkBaseMedia.PrepareConnectionSettings(AppSettings.GetConnectionSettings()); var localDataModel = BaseMapper.GetDataModel(); var remoteDataModel = BaseMapper.GetDataModel(true, true, remoteConnectionStringSetting); var localMediaDetails = localDataModel.MediaDetails.Where(i => i.HistoryVersionNumber == 0 && i.MediaType.ShowInSiteTree && i.MediaType.Name != MediaTypeEnum.RootPage.ToString()).ToList(); var remoteMediaDetails = remoteDataModel.MediaDetails.Where(i => i.HistoryVersionNumber == 0 && i.MediaType.ShowInSiteTree && i.MediaType.Name != MediaTypeEnum.RootPage.ToString()).ToList(); var localSettings = localDataModel.AllSettings.FirstOrDefault(); var remoteSettings = remoteDataModel.AllSettings.FirstOrDefault(); if (localSettings.GlobalCodeInBody != remoteSettings.GlobalCodeInBody) { AddMessage("Settings", $"The setting: 'GlobalCodeInBody' is different"); } if (localSettings.GlobalCodeInHead != remoteSettings.GlobalCodeInHead) { AddMessage("Settings", $"The setting: 'GlobalCodeInHead' is different"); } foreach (var localMediaDetail in localMediaDetails) { var remoteMediaDetail = remoteMediaDetails.FirstOrDefault(i => i.MediaID == localMediaDetail.MediaID && i.LanguageID == localMediaDetail.LanguageID); if (remoteMediaDetail != null) { CompareLocalAndRemoteMediaDetail(localMediaDetail, remoteMediaDetail); } else { var found = remoteMediaDetails.FirstOrDefault(i => i.CachedVirtualPath == localMediaDetail.CachedVirtualPath && i.LanguageID == localMediaDetail.LanguageID); if (found != null) { //AddMessage("Different MediaID's but the same cached virtual path", $"Local: {localMediaDetail.CachedVirtualPath} is '{localMediaDetail.MediaID}' | Remote: {found.CachedVirtualPath} is '{found.MediaID}'"); CompareLocalAndRemoteMediaDetail(localMediaDetail, found); } else { AddMessage("Does not exist on remote", $"{localMediaDetail.CachedVirtualPath}"); } } } DeployMessages.DataSource = _deployMessages; DeployMessages.DataBind(); } catch (Exception ex) { ErrorHelper.LogException(ex); DisplayErrorMessage(ex.Message, ErrorHelper.CreateError(ex)); } }
private void Application_BeginRequest(Object source, EventArgs e) { var installerPath = "~/Installer/"; var absInstallerUrl = URIHelper.ConvertToAbsUrl(installerPath); var absInstallerPath = URIHelper.ConvertToAbsPath(installerPath); if (Request.CurrentExecutionFilePathExtension == "" && !Request.Url.AbsoluteUri.StartsWith(absInstallerUrl)) { if (Directory.Exists(absInstallerPath) && AppSettings.EnableInstaller) { Response.Redirect(installerPath); } } if (AppSettings.IsRunningOnProd && AppSettings.ForceWWWRedirect) { var isSubDomain = (Request.Url.AbsoluteUri.Split('.').Length > 2); var isLocalHost = Request.Url.Host.StartsWith("localhost"); if (!Request.Url.Host.StartsWith("www.") && !isLocalHost && !isSubDomain) { Response.RedirectPermanent(Request.Url.AbsoluteUri.Replace("://", "://www.")); } } BaseService.AddResponseHeaders(); var virtualPathRequest = HttpContext.Current.Request.Path.EndsWith("/"); if (virtualPathRequest) { Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); Response.Cache.SetNoStore(); } if (isFirstApplicationRequest) { ContextHelper.ClearAllMemoryCache(); FrameworkBaseMedia.InitConnectionSettings(AppSettings.GetConnectionSettings()); isFirstApplicationRequest = false; } if (Request.Url.AbsolutePath.Contains("robots.txt")) { var absPath = URIHelper.ConvertToAbsPath(Request.Url.AbsolutePath); if (File.Exists(absPath)) { var fileContent = File.ReadAllText(absPath); var parsedContent = ParserHelper.ParseData(fileContent, BasePage.GetDefaultTemplateVars("")); BaseService.WriteText(parsedContent); } } }
public BasePage() { if (FrameworkSettings.Current == null) { FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByVirtualPath("", true); } AddDefaultTemplateVars(); }
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()); }