/// <summary> /// OnButtonCreated event handler. /// </summary> protected void ucUIToolbar_OnButtonCreated(object sender, UniMenuArgs e) { if ((e.UIElement == null) || (e.ButtonControl == null)) { return; } switch (e.UIElement.ElementName.ToLowerCSafe()) { case "onsitedelete": if (isRootDocument) { DisableButton(e, GetString("onsitedit.deleteroot")); } break; case "onsitesave": if (e.ButtonControl != null) { string saveEnabledTooltip = GetString("onsiteedit.saveenabledtooltip"); string saveDisabledTooltip = GetString("onsiteedit.savedisabledtooltip"); e.ButtonControl.CssClass = "BigButtonDisabled OESaveButton"; e.ButtonControl.Attributes.Add("data-enabledTooltip", saveEnabledTooltip); e.ButtonControl.Attributes.Add("data-disabledTooltip", saveDisabledTooltip); e.ButtonControl.ToolTip = saveDisabledTooltip; } break; case "onsiteclose": case "onsitesignout": { string script = string.Empty; // Show javascript confirmation when the document is not found or published if (IsPageNotFound || ((CurrentPageInfo != null) && !CurrentPageInfo.IsPublished && URLRewriter.PageNotFoundForNonPublished(SiteContext.CurrentSiteName))) { script = "if (!confirm(" + ScriptHelper.GetLocalizedString("onsiteedit.signout404confirmation") + ")) { return false; } "; is404 = true; } // Sign out postback script string eventCode = (e.UIElement.ElementName.ToLowerCSafe() == "onsitesignout") ? "signout" : "changeviewmode"; script += ControlsHelper.GetPostBackEventReference(this, eventCode); script = checkChanges + script; e.ButtonControl.Attributes.Add("onclick", script); } break; case "onsitecmsdesk": { string buttonScript = String.Format("self.location.href = '{0}?nodeid={1}&returnviewmode=editlive';", ResolveUrl(UIHelper.GetAdministrationUrl()), NodeId); buttonScript = checkChanges + buttonScript; e.ButtonControl.Attributes.Add("onclick", buttonScript); } break; } }
/// <summary> /// PreInit event handler /// </summary> protected override void OnPreInit(EventArgs e) { // Handle the rewrite interception if (URLRewriter.FixRewriteRedirect && URLRewriter.HandleRewriteRedirect()) { URLRewriter.PerformPlannedRedirect(); } base.OnPreInit(e); }
public void RewriteMalformedPath_should_parse_out_invalid_characters(string url) { var request = new DefaultHttpContext().Request; request.Method = "GET"; request.Path = new PathString(url); var context = new RewriteContext { HttpContext = request.HttpContext }; URLRewriter.RewriteMalformedPath(context); Assert.IsFalse(request.Path.Value.Contains(@"//")); }
/// <summary> /// Processes the specified file. /// </summary> /// <param name="fileGuid">File guid</param> protected void ProcessFile(Guid fileGuid) { // Get the file ForumAttachmentInfo fileInfo = ForumAttachmentInfoProvider.GetForumAttachmentInfoWithoutBinary(fileGuid, CMSContext.CurrentSiteName); if (fileInfo != null) { #region "Security" // Indicates whether current user is granted to see this attachment bool attachmentAllowed = false; // Get forum ForumInfo fi = ForumInfoProvider.GetForumInfo(fileInfo.AttachmentForumID); if (fi != null) { // Check acess if (ForumViewer.CheckPermission("AccessToForum", SecurityHelper.GetSecurityAccessEnum(fi.ForumAccess, 6), fi.ForumGroupID, fi.ForumID)) { attachmentAllowed = true; } } // If attachment is not allowed for current user, redirect to the access denied page if (!attachmentAllowed) { URLHelper.Redirect(URLRewriter.AccessDeniedPageURL(CurrentSiteName)); } #endregion bool resizeImage = (ImageHelper.IsMimeImage(fileInfo.AttachmentMimeType) && ForumAttachmentInfoProvider.CanResizeImage(fileInfo, Width, Height, MaxSideSize)); // Get the data if ((outputFile == null) || (outputFile.ForumAttachment == null)) { outputFile = new CMSOutputForumAttachment(fileInfo, fileInfo.AttachmentBinary); outputFile.Width = Width; outputFile.Height = Height; outputFile.MaxSideSize = MaxSideSize; outputFile.Resized = resizeImage; } } }
/// <summary> /// Process the detail action. /// </summary> public ActionResult Detail() { // Prepare the data for view TreeNode document = TreeHelper.GetDocument(CMSContext.CurrentSiteName, "/News/" + RouteData.Values["id"], CMSContext.PreferredCultureCode, true, "CMS.News", true); if (document != null) { document.SetValue("NewsTitle", document.GetValue("NewsTitle")); ViewData["Document"] = document; } else { // Document not found URLRewriter.PageNotFound(); return(null); } return(View()); }
/// <summary> /// OnButtonCreated event handler. /// </summary> protected void ucUIToolbar_OnButtonCreated(object sender, UniMenuArgs e) { if ((e.UIElement == null) || (e.ButtonControl == null)) { return; } switch (e.UIElement.ElementName.ToLowerCSafe()) { case "onsitedelete": if (isRootDocument) { DisableButton(e, GetString("onsitedit.deleteroot")); } break; case "onsiteclose": case "onsitesignout": { string script = string.Empty; // Show javascript confirmation when the document is not found or published if (IsPageNotFound || ((CurrentPageInfo != null) && !CurrentPageInfo.IsPublished && URLRewriter.PageNotFoundForNonPublished(CMSContext.CurrentSiteName))) { script = "if (!confirm('" + GetString("onsiteedit.signout404confirmation") + "')) { return false; } "; is404 = true; } // Sign out postback script string eventCode = (e.UIElement.ElementName.ToLowerCSafe() == "onsitesignout") ? "signout" : "changeviewmode"; script += ControlsHelper.GetPostBackEventReference(this, eventCode); e.ButtonControl.Attributes.Add("onclick", script); } break; } }
/// <summary> /// Processes the specified file and returns the data to the output stream. /// </summary> /// <param name="attachmentGuid">Attachment guid</param> protected void ProcessFile(Guid attachmentGuid) { AttachmentInfo atInfo = null; bool requiresData = true; // Check if it is necessary to load the file data if (useClientCache && IsLiveSite && AllowClientCache) { // If possibly cached by client, do not load data (may not be sent) string ifModifiedString = Request.Headers["If-Modified-Since"]; if (ifModifiedString != null) { requiresData = false; } } // If output data available from cache, do not require loading the data byte[] cachedData = GetCachedOutputData(); if (cachedData != null) { requiresData = false; } // Get AttachmentInfo object if (!IsLiveSite) { // Not livesite mode - get latest version if (node != null) { atInfo = DocumentHelper.GetAttachment(node, attachmentGuid, TreeProvider, true); } else { atInfo = DocumentHelper.GetAttachment(attachmentGuid, TreeProvider, CurrentSiteName); } } else { if (!requiresData || AttachmentManager.StoreFilesInFileSystem(CurrentSiteName)) { // Do not require data from DB - Not necessary or available from file system atInfo = AttachmentManager.GetAttachmentInfoWithoutBinary(attachmentGuid, CurrentSiteName); } else { // Require data from DB - Stored in DB atInfo = AttachmentManager.GetAttachmentInfo(attachmentGuid, CurrentSiteName); } // If attachment not found, if (allowLatestVersion && ((atInfo == null) || (latestForHistoryId > 0) || (atInfo.AttachmentDocumentID == latestForDocumentId))) { // Get latest version if (node != null) { atInfo = DocumentHelper.GetAttachment(node, attachmentGuid, TreeProvider, true); } else { atInfo = DocumentHelper.GetAttachment(attachmentGuid, TreeProvider, CurrentSiteName); } // If not attachment for the required document, do not return if ((atInfo.AttachmentDocumentID != latestForDocumentId) && (latestForHistoryId == 0)) { atInfo = null; } else { mIsLatestVersion = true; } } } if (atInfo != null) { // Temporary attachment is always latest version if (atInfo.AttachmentFormGUID != Guid.Empty) { mIsLatestVersion = true; } bool checkPublishedFiles = AttachmentManager.CheckPublishedFiles(CurrentSiteName); bool checkFilesPermissions = AttachmentManager.CheckFilesPermissions(CurrentSiteName); // Get the document node if ((node == null) && (checkPublishedFiles || checkFilesPermissions)) { // Try to get data from cache using (CachedSection <TreeNode> cs = new CachedSection <TreeNode>(ref node, CacheMinutes, !allowLatestVersion, null, "getfilenodebydocumentid", atInfo.AttachmentDocumentID)) { if (cs.LoadData) { // Get the document node = TreeProvider.SelectSingleDocument(atInfo.AttachmentDocumentID, false); // Cache the document CacheNode(cs, node); } } } bool secured = false; if ((node != null) && checkFilesPermissions) { secured = (node.IsSecuredNode == 1); // Check secured pages if (secured) { URLRewriter.CheckSecuredAreas(CurrentSiteName, false, ViewMode); } if (node.RequiresSSL == 1) { URLRewriter.RequestSecurePage(false, node.RequiresSSL, ViewMode, CurrentSiteName); } // Check permissions bool checkPermissions = false; switch (URLRewriter.CheckPagePermissions(CurrentSiteName)) { case PageLocationEnum.All: checkPermissions = true; break; case PageLocationEnum.SecuredAreas: checkPermissions = secured; break; } // Check the read permission for the page if (checkPermissions) { if (CurrentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Read) == AuthorizationResultEnum.Denied) { URLHelper.Redirect(URLRewriter.AccessDeniedPageURL(CurrentSiteName)); } } } bool resizeImage = (ImageHelper.IsImage(atInfo.AttachmentExtension) && AttachmentManager.CanResizeImage(atInfo, Width, Height, MaxSideSize)); // If the file should be redirected, redirect the file if (!mIsLatestVersion && IsLiveSite && SettingsKeyProvider.GetBoolValue(CurrentSiteName + ".CMSRedirectFilesToDisk")) { if (AttachmentManager.StoreFilesInFileSystem(CurrentSiteName)) { string path = null; if (!resizeImage) { path = AttachmentManager.GetFilePhysicalURL(CurrentSiteName, atInfo.AttachmentGUID.ToString(), atInfo.AttachmentExtension); } else { int[] newDim = ImageHelper.EnsureImageDimensions(Width, Height, MaxSideSize, atInfo.AttachmentImageWidth, atInfo.AttachmentImageHeight); path = AttachmentManager.GetFilePhysicalURL(CurrentSiteName, atInfo.AttachmentGUID.ToString(), atInfo.AttachmentExtension, newDim[0], newDim[1]); } // If path is valid, redirect if (path != null) { // Check if file exists string filePath = Server.MapPath(path); if (File.Exists(filePath)) { outputFile = NewOutputFile(); outputFile.IsSecured = secured; outputFile.RedirectTo = path; outputFile.Attachment = atInfo; } } } } // Get the data if ((outputFile == null) || (outputFile.Attachment == null)) { outputFile = NewOutputFile(atInfo, null); outputFile.Width = Width; outputFile.Height = Height; outputFile.MaxSideSize = MaxSideSize; outputFile.SiteName = CurrentSiteName; outputFile.Resized = resizeImage; // Load the data if required if (requiresData) { // Try to get the physical file, if not latest version if (!mIsLatestVersion) { EnsurePhysicalFile(outputFile); } bool loadData = string.IsNullOrEmpty(outputFile.PhysicalFile); // Load data if necessary if (loadData) { if (atInfo.AttachmentBinary != null) { // Load from the attachment outputFile.LoadData(atInfo.AttachmentBinary, AttachmentManager); } else { // Load from the disk byte[] data = AttachmentManager.GetFile(atInfo, CurrentSiteName); outputFile.LoadData(data, AttachmentManager); } // Save data to the cache, if not latest version if (!mIsLatestVersion && (CacheMinutes > 0)) { SaveOutputDataToCache(outputFile.OutputData, GetOutputDataDependency(outputFile.Attachment)); } } } else if (cachedData != null) { // Load the cached data if available outputFile.OutputData = cachedData; } } if (outputFile != null) { outputFile.IsSecured = secured; // Add node data if (node != null) { outputFile.AliasPath = node.NodeAliasPath; outputFile.CultureCode = node.DocumentCulture; outputFile.FileNode = node; // Set the file validity if (IsLiveSite && !mIsLatestVersion && checkPublishedFiles) { outputFile.ValidFrom = ValidationHelper.GetDateTime(node.GetValue("DocumentPublishFrom"), DateTime.MinValue); outputFile.ValidTo = ValidationHelper.GetDateTime(node.GetValue("DocumentPublishTo"), DateTime.MaxValue); // Set the published flag outputFile.IsPublished = node.IsPublished; } } } } }
/// <summary> /// Sends the given file within response. /// </summary> /// <param name="file">File to send</param> protected void SendFile(CMSOutputFile file) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); // Set the revalidation SetRevalidation(); // Send the file if ((file != null) && file.IsValid) { // Redirect if the file should be redirected if (file.RedirectTo != "") { // Log hit or activity before redirecting LogEvent(file); if (StorageHelper.IsExternalStorage) { string url = File.GetFileUrl(file.RedirectTo, CurrentSiteName); if (!string.IsNullOrEmpty(url)) { URLHelper.Redirect(url, true, CurrentSiteName); } } URLHelper.Redirect(file.RedirectTo, true, CurrentSiteName); } // Check authentication if secured file if (file.IsSecured) { URLRewriter.CheckSecured(CurrentSiteName, ViewMode); } // Prepare etag string etag = file.CultureCode.ToLower(); if (file.Attachment != null) { etag += "|" + file.Attachment.AttachmentGUID + "|" + file.Attachment.AttachmentLastModified.ToUniversalTime(); } if (file.IsSecured) { // For secured files, add user name to etag etag += "|" + HttpContext.Current.User.Identity.Name; } // Put etag into "" etag = "\"" + etag + "\""; // Client caching - only on the live site if (useClientCache && AllowCache && AllowClientCache && ETagsMatch(etag, file.LastModified)) { // Set the file time stamps to allow client caching SetTimeStamps(file); RespondNotModified(etag, !file.IsSecured); return; } // If physical file not present, try to load if (file.PhysicalFile == null) { EnsurePhysicalFile(outputFile); } // If the output data should be cached, return the output data bool cacheOutputData = false; if (file.Attachment != null) { // Cache data if allowed if (!LatestVersion && (CacheMinutes > 0)) { cacheOutputData = CacheHelper.CacheImageAllowed(CurrentSiteName, file.Attachment.AttachmentSize); } } // Ensure the file data if physical file not present if (!file.DataLoaded && (file.PhysicalFile == "")) { byte[] cachedData = GetCachedOutputData(); if (file.EnsureData(cachedData)) { if ((cachedData == null) && cacheOutputData) { SaveOutputDataToCache(file.OutputData, GetOutputDataDependency(file.Attachment)); } } } // Send the file if ((file.OutputData != null) || (file.PhysicalFile != "")) { // Setup the mime type - Fix the special types string mimetype = file.MimeType; if (file.Attachment != null) { string extension = file.Attachment.AttachmentExtension; switch (extension.ToLower()) { case ".flv": mimetype = "video/x-flv"; break; } // Prepare response Response.ContentType = mimetype; SetDisposition(file.Attachment.AttachmentName, extension); // Setup Etag property ETag = etag; // Set if resumable downloads should be supported AcceptRange = !IsExtensionExcludedFromRanges(extension); } if (useClientCache && AllowCache) { // Set the file time stamps to allow client caching SetTimeStamps(file); Response.Cache.SetETag(etag); } else { SetCacheability(); } // Log hit or activity LogEvent(file); // Add the file data if ((file.PhysicalFile != "") && (file.OutputData == null)) { // Stream the file from the file system file.OutputData = WriteFile(file.PhysicalFile, cacheOutputData); } else { // Use output data of the file in memory if present WriteBytes(file.OutputData); } } else { NotFound(); } } else { NotFound(); } CompleteRequest(); }
protected void Page_Load(object sender, EventArgs e) { DebugHelper.SetContext("GetFile"); // Load the site name LoadSiteName(); // Check the site if (CurrentSiteName == "") { throw new Exception("[GetFile.aspx]: Site not running."); } // Validate the culture PreferredCultureOnDemand culture = new PreferredCultureOnDemand(); URLRewriter.ValidateCulture(CurrentSiteName, culture, null); // Set campaign if (IsLiveSite) { // Store campaign name if present string campaign = AnalyticsHelper.CurrentCampaign(CurrentSiteName); if (!String.IsNullOrEmpty(campaign)) { PageInfo pi = CMSContext.CurrentPageInfo; // Log campaign if ((pi != null) && AnalyticsHelper.IsLoggingEnabled(CurrentSiteName, pi.NodeAliasPath) && AnalyticsHelper.SetCampaign(campaign, CurrentSiteName, pi.NodeAliasPath)) { CMSContext.Campaign = campaign; } } } int cacheMinutes = CacheMinutes; // Try to get data from cache using (CachedSection <CMSOutputFile> cs = new CachedSection <CMSOutputFile>(ref outputFile, cacheMinutes, true, null, "getfile", CurrentSiteName, CacheHelper.BaseCacheKey, Request.QueryString)) { if (cs.LoadData) { // Store current value and temporarly disable caching bool cached = cs.Cached; cs.Cached = false; // Process the file ProcessAttachment(); // Restore cache settings - data were loaded cs.Cached = cached; if (cs.Cached) { // Do not cache if too big file which would be stored in memory if ((outputFile != null) && (outputFile.Attachment != null) && !CacheHelper.CacheImageAllowed(CurrentSiteName, outputFile.Attachment.AttachmentSize) && !AttachmentManager.StoreFilesInFileSystem(CurrentSiteName)) { cacheMinutes = largeFilesCacheMinutes; } if (cacheMinutes > 0) { // Prepare the cache dependency CacheDependency cd = null; if (outputFile != null) { string[] dependencies = new string[] { "node|" + CurrentSiteName.ToLower() + "|" + outputFile.AliasPath.ToLower(), "" }; // Do not cache if too big file which would be stored in memory if (outputFile.Attachment != null) { if (!CacheHelper.CacheImageAllowed(CurrentSiteName, outputFile.Attachment.AttachmentSize) && !AttachmentManager.StoreFilesInFileSystem(CurrentSiteName)) { cacheMinutes = largeFilesCacheMinutes; } dependencies[1] = "attachment|" + outputFile.Attachment.AttachmentGUID.ToString().ToLower(); } cd = CacheHelper.GetCacheDependency(dependencies); } if (cd == null) { // Set default dependency if (guid != Guid.Empty) { // By attachment GUID cd = CacheHelper.GetCacheDependency(new string[] { "attachment|" + guid.ToString().ToLower() }); } else if (nodeGuid != Guid.Empty) { // By node GUID cd = CacheHelper.GetCacheDependency(new string[] { "nodeguid|" + CurrentSiteName.ToLower() + "|" + nodeGuid.ToString().ToLower() }); } else if (aliasPath != null) { // By node alias path cd = CacheHelper.GetCacheDependency(new string[] { "node|" + CurrentSiteName.ToLower() + "|" + aliasPath.ToLower() }); } } cs.CacheDependency = cd; } // Cache the data cs.CacheMinutes = cacheMinutes; cs.Data = outputFile; } } } // Do not cache images in the browser if cache is not allowed if (LatestVersion) { useClientCache = false; } // Send the data SendFile(outputFile); DebugHelper.ReleaseContext(); }
/// <summary> /// Processes the specified version of the file and returns the data to the output stream. /// </summary> /// <param name="attachmentGuid">Attachment GUID</param> /// <param name="versionHistoryId">Document version history ID</param> protected void ProcessFile(Guid attachmentGuid, int versionHistoryId) { AttachmentInfo atInfo = GetFile(attachmentGuid, versionHistoryId); if (atInfo != null) { // If attachment is image, try resize byte[] mFile = atInfo.AttachmentBinary; if (mFile != null) { string mimetype = null; if (ImageHelper.IsImage(atInfo.AttachmentExtension)) { if (AttachmentManager.CanResizeImage(atInfo, Width, Height, MaxSideSize)) { // Do not search thumbnail on the disk mFile = AttachmentManager.GetImageThumbnail(atInfo, CurrentSiteName, Width, Height, MaxSideSize, false); mimetype = "image/jpeg"; } } if (mFile != null) { outputFile = NewOutputFile(atInfo, mFile); } else { outputFile = NewOutputFile(); } outputFile.Height = Height; outputFile.Width = Width; outputFile.MaxSideSize = MaxSideSize; outputFile.MimeType = mimetype; } // Get the file document if (node == null) { node = TreeProvider.SelectSingleDocument(atInfo.AttachmentDocumentID); } if (node != null) { // Check secured area SiteInfo si = SiteInfoProvider.GetSiteInfo(node.NodeSiteID); if (si != null) { if (pi == null) { pi = PageInfoProvider.GetPageInfo(si.SiteName, node.NodeAliasPath, node.DocumentCulture, node.DocumentUrlPath, false); } if (pi != null) { URLRewriter.RequestSecurePage(pi, false, ViewMode, CurrentSiteName); URLRewriter.CheckSecuredAreas(CurrentSiteName, pi, false, ViewMode); } } // Check the permissions for the document if ((CurrentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Read) == AuthorizationResultEnum.Allowed) || (node.NodeOwner == CurrentUser.UserID)) { if (outputFile == null) { outputFile = NewOutputFile(); } outputFile.AliasPath = node.NodeAliasPath; outputFile.CultureCode = node.DocumentCulture; if (IsLiveSite && AttachmentManager.CheckPublishedFiles(CurrentSiteName)) { outputFile.IsPublished = node.IsPublished; } outputFile.FileNode = node; } else { outputFile = null; } } } }
/// <summary> /// Sends the given file within response. /// </summary> /// <param name="file">File to send</param> protected void SendFile(CMSOutputMediaFile file) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); // Set the revalidation SetRevalidation(); // Send the file if (file != null) { #region "Security" // Check if user is allowed to see the library file content if required bool checkPermissions = SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".CMSCheckMediaFilePermissions"); if (checkPermissions) { // Check the library access for the current user and stop file processing if not allowed MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(file.MediaFile.FileLibraryID); if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "LibraryAccess")) { URLHelper.Redirect(URLRewriter.AccessDeniedPageURL(CurrentSiteName)); return; } } #endregion // Prepare etag string etag = ""; if (file.MediaFile != null) { etag += file.MediaFile.FileModifiedWhen.ToUniversalTime(); } // Put etag into "" etag = String.Format("\"{0}\"", etag); // Client caching - only on the live site if (useClientCache && AllowCache && AllowClientCache && ETagsMatch(etag, file.LastModified)) { // Set the file time stamps to allow client caching SetTimeStamps(file); RespondNotModified(etag, true); return; } // If physical file not present, try to load EnsurePhysicalFile(outputFile); // If the output data should be cached, return the output data bool cacheOutputData = false; if ((file.MediaFile != null) && (CacheMinutes > 0)) { cacheOutputData = CacheHelper.CacheImageAllowed(CurrentSiteName, (int)file.MediaFile.FileSize); } // Ensure the file data if physical file not present if (!file.DataLoaded && (file.PhysicalFile == "")) { byte[] cachedData = GetCachedOutputData(); if (file.EnsureData(cachedData)) { if ((cachedData == null) && cacheOutputData) { SaveOutputDataToCache(file.OutputData, GetOutputDataDependency(file.MediaFile)); } } } // Send the file if ((file.OutputData != null) || (file.PhysicalFile != "")) { // Setup the mime type - Fix the special types string mimetype = file.MimeType; string extension = file.FileExtension; switch (extension.ToLower()) { case ".flv": mimetype = "video/x-flv"; break; } // Prepare response Response.ContentType = mimetype; SetDisposition(file.FileName + extension, extension); // Setup Etag property ETag = etag; // Set if resumable downloads should be supported AcceptRange = !IsExtensionExcludedFromRanges(extension); if (useClientCache && AllowCache) { // Set the file time stamps to allow client caching SetTimeStamps(file); Response.Cache.SetETag(etag); } // Add the file data if ((file.PhysicalFile != "") && (file.OutputData == null)) { // Stream the file from the file system file.OutputData = WriteFile(file.PhysicalFile, cacheOutputData); } else { // Use output data of the file in memory if present WriteBytes(file.OutputData); } } else { this.NotFound(); } } else { this.NotFound(); } CompleteRequest(); }
protected void Page_Load(object sender, EventArgs e) { // Switch the view mode CMSContext.ViewMode = ViewModeEnum.Preview; // Get the document int nodeId = 0; if (Request.QueryString["nodeid"] != null) { nodeId = ValidationHelper.GetInteger(Request.QueryString["nodeid"], 0); } string siteName = CMSContext.CurrentSiteName; TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); TreeNode node = null; // Check split mode bool isSplitMode = CMSContext.DisplaySplitMode; bool combineWithDefaultCulture = isSplitMode ? false : SiteInfoProvider.CombineWithDefaultCulture(siteName); // Get the document node = tree.SelectSingleNode(nodeId, CMSContext.PreferredCultureCode, combineWithDefaultCulture); // Redirect to the live URL if (node != null) { // If no workflow defined, hide the menu bar WorkflowManager wm = new WorkflowManager(tree); WorkflowInfo wi = wm.GetNodeWorkflow(node); if (wi == null) { headersize = "0"; } else { // Get current step info WorkflowStepInfo si = wm.GetStepInfo(node); if (si != null) { switch (si.StepName.ToLower()) { case "published": case "archived": headersize = "0"; break; } } } // Check the document availability if (!node.DocumentCulture.Equals(CMSContext.PreferredCultureCode, StringComparison.InvariantCultureIgnoreCase) && (!SiteInfoProvider.CombineWithDefaultCulture(siteName) || !node.DocumentCulture.Equals(CultureHelper.GetDefaultCulture(siteName), StringComparison.InvariantCultureIgnoreCase))) { viewpage = "~/CMSMessages/PageNotAvailable.aspx?reason=missingculture"; } else { // Use permanent URL to get proper preview mode viewpage = URLRewriter.GetEditingUrl(node); } } else { viewpage = isSplitMode ? "~/CMSModules/Content/CMSDesk/New/NewCultureVersion.aspx" + URLHelper.Url.Query : "~/CMSMessages/PageNotAvailable.aspx?reason=missingculture&showlink=false"; } // Register synchronization script for split mode if (isSplitMode) { RegisterSplitModeSync(false, false); } viewpage = ResolveUrl(viewpage); }
protected void Page_Load(object sender, EventArgs e) { ScriptHelper.RegisterProgress(this); ScriptHelper.RegisterScriptFile(this, "cmsedit.js"); string notAllowedScript = ScriptHelper.GetScript("var notAllowedAction = '" + GetString("editpage.actionnotallowed") + "';"); ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "notAllowedAction", notAllowedScript); // Get the node ID int nodeId = QueryHelper.GetInteger("nodeid", 0); viewpage = ResolveUrl("~/CMSModules/Content/CMSDesk/Edit/edit.aspx") + URLHelper.Url.Query; string action = QueryHelper.GetString("action", "").ToLower(); string mode = QueryHelper.GetString("mode", "").ToLower(); string elementToCheck = null; switch (mode) { case "edit": elementToCheck = "Page"; break; case "design": elementToCheck = "Design"; break; case "editform": elementToCheck = "EditForm"; break; } // Check UI elements for tabs only if mode is set (skip UI element check for actions, which don't have own UI element like NEW) if (!string.IsNullOrEmpty(elementToCheck)) { if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Content", elementToCheck)) { RedirectToCMSDeskUIElementAccessDenied("CMS.Content", elementToCheck); } } switch (action) { case "newvariant": viewpage = URLHelper.AppendQuery(ResolveUrl("~/CMSModules/OnlineMarketing/Pages/Content/ABTesting/ABVariant/NewPage.aspx"), URLHelper.Url.Query); break; default: // Check if new document desired bool newdocument = (action == "new"); DataClassInfo classInfo = null; if (newdocument) { // Get the class ID int classId = QueryHelper.GetInteger("classid", 0); classInfo = DataClassInfoProvider.GetDataClass(classId); } else { // Get the document TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); node = tree.SelectSingleNode(nodeId, CMSContext.PreferredCultureCode, false); if (node != null) { classInfo = DataClassInfoProvider.GetDataClass(node.NodeClassName); // Register js synchronization script for split mode if (CMSContext.DisplaySplitMode) { RegisterSplitModeSync(false, false); } } } // Check the editing page change if (classInfo != null) { if (CMSContext.ViewMode == ViewModeEnum.EditForm || newdocument) { // If new document, check if new page URL is set if (newdocument) { if (!string.IsNullOrEmpty(classInfo.ClassNewPageURL)) { // Use special settings for new page if (classInfo.ClassNewPageURL.ToLower().EndsWith("/cmsmodules/content/cmsdesk/new/newpage.aspx")) { // Disable onload script loadScript = String.Empty; } viewpage = URLHelper.AppendQuery(ResolveUrl(classInfo.ClassNewPageURL), URLHelper.Url.Query); } } // If existing document, check if editing page URL is set else if (!string.IsNullOrEmpty(classInfo.ClassEditingPageURL)) { viewpage = URLHelper.AppendQuery(ResolveUrl(classInfo.ClassEditingPageURL), URLHelper.Url.Query); } ScriptHelper.RegisterTitleScript(this, GetString("content.ui.form")); } else if (CMSContext.ViewMode == ViewModeEnum.Edit) { // Check if view page URL is set if (!string.IsNullOrEmpty(classInfo.ClassViewPageUrl)) { viewpage = URLHelper.AppendQuery(ResolveUrl(classInfo.ClassViewPageUrl), URLHelper.Url.Query); } else { viewpage = URLRewriter.GetEditingUrl(node); } ScriptHelper.RegisterTitleScript(this, GetString("content.ui.page")); } else if (CMSContext.ViewMode == ViewModeEnum.Design) { // Use permanent URL to get proper design mode viewpage = URLRewriter.GetEditingUrl(node); ScriptHelper.RegisterTitleScript(this, GetString("content.ui.design")); } else { // Use standard URL to get other modes viewpage = ResolveUrl(CMSContext.GetUrl(node.NodeAliasPath, node.DocumentUrlPath)); } } break; } }
protected void Page_Load(object sender, EventArgs e) { // Switch the view mode CMSContext.ViewMode = ViewModeEnum.LiveSite; // Get the document int nodeId = 0; if (Request.QueryString["nodeid"] != null) { nodeId = ValidationHelper.GetInteger(Request.QueryString["nodeid"], 0); } string siteName = CMSContext.CurrentSiteName; TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); TreeNode node = null; // Check split mode bool isSplitMode = CMSContext.DisplaySplitMode; bool combineWithDefaultCulture = isSplitMode ? false : SiteInfoProvider.CombineWithDefaultCulture(siteName); // Get the document node = tree.SelectSingleNode(nodeId, CMSContext.PreferredCultureCode, combineWithDefaultCulture); // Redirect to the live URL string url = null; if (node != null) { // Check if the node is published or available if (!node.DocumentCulture.Equals(CMSContext.PreferredCultureCode, StringComparison.InvariantCultureIgnoreCase) && (!SiteInfoProvider.CombineWithDefaultCulture(siteName) || !node.DocumentCulture.Equals(CultureHelper.GetDefaultCulture(siteName), StringComparison.InvariantCultureIgnoreCase))) { url = "~/CMSMessages/PageNotAvailable.aspx?reason=missingculture"; } if ((url == null) && !node.IsPublished && URLRewriter.PageNotFoundForNonPublished(siteName)) { // Try to find published document in default culture if (SiteInfoProvider.CombineWithDefaultCulture(siteName)) { string defaultCulture = CultureHelper.GetDefaultCulture(siteName); node = tree.SelectSingleNode(nodeId, defaultCulture, false); if ((node != null) && node.IsPublished) { // Do not use document URL path - preferred culture could be changed url = CMSContext.GetUrl(node.NodeAliasPath, null); } } if (url == null) { // Document is not published url = "~/CMSMessages/PageNotAvailable.aspx?reason=notpublished"; } } } else { url = isSplitMode ? "~/CMSModules/Content/CMSDesk/New/NewCultureVersion.aspx" + URLHelper.Url.Query : "~/CMSMessages/PageNotAvailable.aspx?reason=missingculture&showlink=false"; } if (url == null) { // Do not use document URL path - preferred culture could be changed url = CMSContext.GetUrl(node.NodeAliasPath, null); } // Split mode if (CMSContext.DisplaySplitMode) { url = URLHelper.AddParameterToUrl(url, "cmssplitmode", "1"); } URLHelper.Redirect(url); }