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(); }