protected void Page_Load(object sender, EventArgs e) { // Get event NodeID from querystring int eventNodeId = QueryHelper.GetInteger("eventid", 0); int timeZoneId = QueryHelper.GetInteger("timezoneid", 0); if (eventNodeId != 0) { TreeProvider mTree = new TreeProvider(); TreeNode eventInfo = mTree.SelectSingleNode(eventNodeId); if (eventInfo != null && eventInfo.NodeClassName.Equals("cms.bookingevent", StringComparison.InvariantCultureIgnoreCase)) { // Get file content. byte[] fileContent = GetContent(eventInfo, timeZoneId); if (fileContent != null) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); // Prepare response. Response.ContentType = "text/calendar"; // Disposition type - For files "attachment" is default Response.AddHeader("Content-Disposition", "attachment;filename=Reminder.ics"); Response.OutputStream.Write(fileContent, 0, fileContent.Length); //RequestHelper.CompleteRequest(); RequestHelper.EndResponse(); } } } }
/// <summary> /// Sends the given file within response. /// </summary> /// <param name="file">File to send</param> protected void SendFile(CMSOutputResource file) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); // Send the file if ((file != null) && (file.Data != null)) { // Prepare response Response.ContentType = "text/css"; // Client caching - only on the live site if (useClientCache && AllowCache && CacheHelper.CacheImageEnabled(CurrentSiteName) && ETagsMatch(file.Etag, file.LastModified)) { RespondNotModified(file.Etag); return; } if (useClientCache && AllowCache && CacheHelper.CacheImageEnabled(CurrentSiteName)) { SetTimeStamps(file.LastModified); Response.Cache.SetETag(file.Etag); } // Add the file data Response.Write(file.Data); } CompleteRequest(); }
protected void Page_Load(object sender, EventArgs e) { // Check 'ReadData' permission if (CurrentUser != null && CurrentUser.IsAuthorizedPerResource("cms.form", "ReadData")) { // Get file name from querystring string fileName = QueryHelper.GetString("filename", String.Empty); string siteName = QueryHelper.GetString("sitename", CurrentSiteName); if ((ValidationHelper.IsFileName(fileName)) && (siteName != null)) { // Get physical path to the file string filePath = FormHelper.GetFilePhysicalPath(siteName, fileName); if (File.Exists(filePath)) { // Clear response CookieHelper.ClearResponseCookies(); Response.Clear(); // Prepare response string extension = Path.GetExtension(filePath); Response.ContentType = MimeTypeHelper.GetMimetype(extension); // Set the file disposition SetDisposition(fileName, extension); // Get file binary from file system WriteFile(filePath); CompleteRequest(); } } } }
/// <summary> /// Sends the graph. /// </summary> /// <param name="mimeType">Response mime type</param> /// <param name="graph">Raw data to be sent</param> protected void SendGraph(string mimeType, byte[] graph) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); Response.Cache.SetCacheability(HttpCacheability.NoCache); // Prepare response Response.ContentType = mimeType; Response.OutputStream.Write(graph, 0, graph.Length); //RequestHelper.CompleteRequest(); RequestHelper.EndResponse(); }
/// <summary> /// Sends the given file within response. /// </summary> /// <param name="file">File to send</param> protected void SendFile() { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); if (tfi != null) { // Prepare etag string etag = "\"" + tfi.FileID + "\""; // Setup the mime type - Fix the special types string mimetype = tfi.FileMimeType; string extension = tfi.FileExtension; switch (extension.ToLowerCSafe()) { case ".flv": mimetype = "video/x-flv"; break; } // Prepare response Response.ContentType = mimetype; SetDisposition(tfi.FileNumber.ToString(), extension); // Setup Etag property ETag = etag; // Set if resumable downloads should be supported AcceptRange = !IsExtensionExcludedFromRanges(extension); // Add the file data tfi.Generalized.EnsureBinaryData(); WriteBytes(tfi.FileBinary); } else { NotFound(); } CompleteRequest(); }
/// <summary> /// Sends the given file within response. /// </summary> /// <param name="file">File to send</param> protected void SendFile(CMSOutputResource file) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); // Send the file if ((file != null) && (file.Data != null)) { // Prepare response Response.ContentType = "text/css"; // Client caching - only on the live site if (useClientCache && PortalContext.ViewMode.IsLiveSite() && (CacheHelper.CacheImageEnabled(CurrentSiteName)) && ETagsMatch(file.Etag, file.LastModified)) { RespondNotModified(file.Etag, true); return; } if (useClientCache && PortalContext.ViewMode.IsLiveSite() && (CacheHelper.CacheImageEnabled(CurrentSiteName))) { DateTime expires = DateTime.Now; // Send last modified header to allow client caching Response.Cache.SetLastModified(file.LastModified); Response.Cache.SetCacheability(HttpCacheability.Public); if (DocumentBase.AllowClientCache()) { expires = DateTime.Now.AddMinutes(CacheHelper.CacheImageMinutes(CurrentSiteName)); } Response.Cache.SetExpires(expires); Response.Cache.SetETag(file.Etag); } // Add the file data Response.Write(file.Data); } CompleteRequest(); }
/// <summary> /// Sends response to client. /// </summary> /// <param name="message">If not empty then send error response with this message</param> private void SendResponse(string message) { // Clear response CookieHelper.ClearResponseCookies(); Response.Clear(); // Create response data Response.ContentType = "application/x-www-form-urlencoded"; if (String.IsNullOrEmpty(message)) { Response.Write("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><response><error>0</error></response>"); } else { Response.Write("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><response><error>1</error><message>" + message + "</message></response>"); } // Complete response RequestHelper.EndResponse(); }
protected void Page_Load(object sender, EventArgs e) { string hash = QueryHelper.GetString("hash", string.Empty); string path = QueryHelper.GetString("path", string.Empty); // Validate hash if (ValidationHelper.ValidateHash("?path=" + URLHelper.EscapeSpecialCharacters(path), hash, false)) { if (path.StartsWithCSafe("~")) { path = Server.MapPath(path); } // Get file content from blob BlobInfo bi = new BlobInfo(path); // Check if blob exists if (BlobInfoProvider.BlobExists(bi)) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); // Set the revalidation SetRevalidation(); string etag = bi.ETag; DateTime lastModified = ValidationHelper.GetDateTime(bi.GetMetadata(ContainerInfoProvider.LAST_WRITE_TIME), DateTimeHelper.ZERO_TIME); // Set correct response content type SetResponseContentType(path); // Client caching - only on the live site if (AllowCache && AllowClientCache && ETagsMatch(etag, lastModified)) { // Set the file time stamps to allow client caching SetTimeStamps(lastModified); RespondNotModified(etag); return; } Stream stream = BlobInfoProvider.GetBlobContent(bi); SetDisposition(Path.GetFileName(path), Path.GetExtension(path)); // Setup Etag property ETag = etag; if (AllowCache) { // Set the file time stamps to allow client caching SetTimeStamps(lastModified); Response.Cache.SetETag(etag); } else { SetCacheability(); } // Send headers Response.Flush(); Byte[] buffer = new Byte[StorageHelper.BUFFER_SIZE]; int bytesRead = stream.Read(buffer, 0, StorageHelper.BUFFER_SIZE); // Copy data from blob stream to cache while (bytesRead > 0) { // Write the data to the current output stream Response.OutputStream.Write(buffer, 0, bytesRead); // Flush the data to the output Response.Flush(); // Read next part of data bytesRead = stream.Read(buffer, 0, StorageHelper.BUFFER_SIZE); } stream.Close(); CompleteRequest(); } else { NotFound(); } } else { URLHelper.Redirect(ResolveUrl("~/CMSMessages/Error.aspx?title=" + ResHelper.GetString("general.badhashtitle") + "&text=" + ResHelper.GetString("general.badhashtext"))); } }
/// <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(); }
/// <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(); }
/// <summary> /// Sends the given file within response. /// </summary> /// <param name="file">File to send</param> protected void SendFile(CMSOutputMetaFile file) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); // Set the revalidation SetRevalidation(); // Send the file if (file != null) { // Redirect if the file should be redirected if (file.RedirectTo != "") { URLHelper.RedirectPermanent(file.RedirectTo, CurrentSiteName); } string etag = GetFileETag(file); // Client caching - only on the live site if (useClientCache && AllowCache && AllowClientCache && ETagsMatch(etag, file.LastModified)) { // Set correct response content type SetResponseContentType(file); // Set the file time stamps to allow client caching SetTimeStamps(file); RespondNotModified(etag, true); 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 ((CacheMinutes > 0) && (file.MetaFile != null)) { cacheOutputData = CacheHelper.CacheImageAllowed(CurrentSiteName, file.MetaFile.MetaFileSize); } // 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.MetaFile)); } } } // Send the file if ((file.OutputData != null) || (file.PhysicalFile != "")) { // Set correct response content type SetResponseContentType(file); string extension = file.MetaFile.MetaFileExtension; SetDisposition(file.MetaFile.MetaFileName, 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(); } // Add the file data if ((file.PhysicalFile != "") && (file.OutputData == null)) { if (!File.Exists(file.PhysicalFile)) { // File doesn't exist NotFound(); } else { // 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 override void ProcessRequestInternal(HttpContextBase context) { var hash = QueryHelper.GetString("hash", string.Empty); var path = QueryHelper.GetString("path", string.Empty); // Validate hash var settings = new HashSettings { Redirect = false }; if (!ValidationHelper.ValidateHash("?path=" + URLHelper.EscapeSpecialCharacters(path), hash, settings)) { RequestHelper.Respond403(); } if (path.StartsWithCSafe("~")) { path = context.Server.MapPath(path); } var blobPath = AzurePathHelper.GetBlobPath(path); var blob = BlobCollection.Instance.GetOrCreate(blobPath); if (!blob.Exists()) { RequestHelper.Respond404(); } CookieHelper.ClearResponseCookies(); Response.Clear(); SetRevalidation(); var eTag = blob.GetAttribute(a => a.Etag); var lastModified = ValidationHelper.GetDateTime(blob.GetAttribute(a => a.LastModified), DateTimeHelper.ZERO_TIME); SetResponseContentType(path); // Client caching - only on the live site if (AllowCache && AllowClientCache && ETagsMatch(eTag, lastModified)) { // Set the file time stamps to allow client caching SetTimeStamps(lastModified); RespondNotModified(eTag); return; } SetDisposition(Path.GetFileName(path), Path.GetExtension(path)); // Setup Etag property ETag = eTag; if (AllowCache) { // Set the file time stamps to allow client caching SetTimeStamps(lastModified); Response.Cache.SetETag(eTag); } else { SetCacheability(); } WriteFile(path, CacheHelper.CacheImageAllowed(CurrentSiteName, Convert.ToInt32(blob.GetAttribute(a => a.Length)))); CompleteRequest(); }
/// <summary> /// Sends the given file within response. /// </summary> /// <param name="file">File to send</param> protected void SendFile(CMSOutputMetaFile file) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); // Set the revalidation SetRevalidation(); // Send the file if (file != null) { // Redirect if the file should be redirected if (file.RedirectTo != "") { URLHelper.Redirect(file.RedirectTo, true, this.CurrentSiteName); } // Prepare etag string etag = null; if (file.MetaFile != null) { etag += file.MetaFile.MetaFileID; } // 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, true); 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 ((this.CacheMinutes > 0) && (file.MetaFile != null)) { cacheOutputData = CacheHelper.CacheImageAllowed(CurrentSiteName, file.MetaFile.MetaFileSize); } // 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.MetaFile)); } } } // Send the file if ((file.OutputData != null) || (file.PhysicalFile != "")) { // Setup the mime type - Fix the special types string mimetype = file.MimeType; string extension = file.MetaFile.MetaFileExtension; switch (extension.ToLower()) { case ".flv": mimetype = "video/x-flv"; break; } // Prepare response Response.ContentType = mimetype; SetDisposition(file.MetaFile.MetaFileName, 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 { NotFound(); } } else { NotFound(); } CompleteRequest(); }
/// <summary> /// Sends the given file within response. /// </summary> /// <param name="file">File to send</param> protected void SendFile(CMSOutputSharePointFile file) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); SetRevalidation(); if ((file != null) && file.IsValid) { // Prepare etag in "" string etag = "\"" + file.SharePointFilePath + "\""; // Client caching - only on the live site if (useClientCache && AllowCache && ETagsMatch(etag, file.LastModified)) { // Set correct response content type SetResponseContentType(file); SetTimeStamps(file.LastModified); RespondNotModified(etag); return; } // If the output data should be cached, return the output data bool cacheOutputData = false; if (file.OutputData != null) { cacheOutputData = CacheHelper.CacheImageAllowed(CurrentSiteName, file.OutputData.Length); } // Ensure the file data if (!file.DataLoaded) { byte[] cachedData = GetCachedOutputData(); // Ensure data are retrieved from SharePoint if (file.EnsureData(cachedData)) { if ((cachedData == null) && cacheOutputData) { SaveOutputDataToCache(file.OutputData, null); } } } // Send the file if (file.OutputData != null) { byte[] data; // Check if the request is for partial data (Range HTTP header) long[,] rangePosition = GetRange(file.OutputData.Length, HttpContext.Current); // Send all file contens if (rangePosition.GetUpperBound(0) == 0) { // Set correct response content type SetResponseContentType(file); // get file name without the path string fileName = Path.GetFileName(file.SharePointFilePath); SetDisposition(fileName, file.FileExtension); // Setup Etag property ETag = etag; // Set if resumable downloads should be supported AcceptRange = !IsExtensionExcludedFromRanges(file.FileExtension); if (useClientCache && AllowCache) { SetTimeStamps(file.LastModified); Response.Cache.SetETag(etag); } else { SetCacheability(); } data = file.OutputData; } // Send partial contens else { data = new byte[file.OutputData.Length - rangePosition[0, ResponseDataSender.RANGE_START]]; // Get part of file Array.Copy(file.OutputData, rangePosition[0, ResponseDataSender.RANGE_START], data, 0, data.Length); } // Use output data of the file in memory if present WriteBytes(data); } else { NotFound(); } } else { NotFound(); } CompleteRequest(); }
/// <summary> /// Sends the given file within response. /// </summary> /// <param name="file">File to send</param> protected void SendFile(CMSOutputSharePointFile file) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); if ((file != null) && file.IsValid) { // Prepare etag in "" string etag = "\"" + file.SharePointFilePath + "\""; // Client caching - only on the live site if (useClientCache && AllowCache && CacheHelper.CacheImageEnabled(CurrentSiteName) && ETagsMatch(etag, file.LastModified)) { RespondNotModified(etag, true); return; } // If the output data should be cached, return the output data bool cacheOutputData = false; if (file.OutputData != null) { cacheOutputData = CacheHelper.CacheImageAllowed(CurrentSiteName, file.OutputData.Length); } // Ensure the file data if (!file.DataLoaded) { byte[] cachedData = GetCachedOutputData(); // Ensure data are retrieved from SharePoint if (file.EnsureData(cachedData)) { if ((cachedData == null) && cacheOutputData) { SaveOutputDataToCache(file.OutputData, null); } } } // Send the file if (file.OutputData != null) { byte[] data = null; // Check if the request is for partial data (Range HTTP header) long[,] rangePosition = GetRange(file.OutputData.Length, HttpContext.Current); // Send all file contens if (rangePosition.GetUpperBound(0) == 0) { // Setup the mime type - Fix the special types string mimetype = file.MimeType; switch (file.FileExtension.ToLower()) { case ".flv": mimetype = "video/x-flv"; break; } // Prepare response Response.ContentType = mimetype; // get file name without the path string fileName = Path.GetFileName(file.SharePointFilePath); SetDisposition(fileName, file.FileExtension); // Setup Etag property ETag = etag; // Set if resumable downloads should be supported AcceptRange = !IsExtensionExcludedFromRanges(file.FileExtension); if (useClientCache && AllowCache && (CacheHelper.CacheImageEnabled(CurrentSiteName))) { DateTime expires = DateTime.Now; // Send last modified header to allow client caching Response.Cache.SetLastModified(file.LastModified); Response.Cache.SetCacheability(HttpCacheability.Public); if (DocumentBase.AllowClientCache() && DocumentBase.UseFullClientCache) { expires = DateTime.Now.AddMinutes(CacheHelper.CacheImageMinutes(CurrentSiteName)); } Response.Cache.SetExpires(expires); Response.Cache.SetETag(etag); } data = file.OutputData; } // Send partial contens else { data = new byte[file.OutputData.Length - rangePosition[0, RANGE_START]]; // Get part of file Array.Copy(file.OutputData, rangePosition[0, RANGE_START], data, 0, data.Length); } // Use output data of the file in memory if present WriteBytes(data); } else { NotFound(); } } else { NotFound(); } CompleteRequest(); }
/// <summary> /// Sends the given file within response. /// </summary> /// <param name="file">File to send</param> protected void SendFile(CMSOutputAvatar file) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); // Set the revalidation SetRevalidation(); // Send the file if (file != null) { // Redirect if the file should be redirected if (file.RedirectTo != "") { URLHelper.Redirect(file.RedirectTo, true, CurrentSiteName); } // Prepare etag string etag = file.LastModified.ToString(); // Client caching - only on the live site if (useClientCache && AllowCache && AllowClientCache && ETagsMatch(etag, file.LastModified)) { RespondNotModified(etag, true); return; } // If physical file not present, try to load if (file.PhysicalFile == null) { EnsurePhysicalFile(outputFile); } // Ensure the file data if physical file not present if (!file.DataLoaded && (file.PhysicalFile == "")) { byte[] cachedData = GetCachedOutputData(); if (file.EnsureData(cachedData)) { if ((cachedData == null) && (this.CacheMinutes > 0)) { SaveOutputDataToCache(file.OutputData, GetOutputDataDependency(file.Avatar)); } } } // Send the file if ((file.OutputData != null) || (file.PhysicalFile != "")) { // Setup the mime type - Fix the special types string mimetype = file.MimeType; string extension = file.Avatar.AvatarFileExtension; switch (extension.ToLower()) { case ".flv": mimetype = "video/x-flv"; break; } // Prepare response Response.ContentType = mimetype; SetDisposition(file.Avatar.AvatarFileName, extension); ETag = etag; // Set if resumable downloads should be supported AcceptRange = !IsExtensionExcludedFromRanges(extension); if (useClientCache && AllowCache) { DateTime expires = DateTime.Now; // Send last modified header to allow client caching Response.Cache.SetLastModified(file.LastModified); Response.Cache.SetCacheability(HttpCacheability.Public); if (AllowClientCache) { expires = DateTime.Now.AddMinutes(this.ClientCacheMinutes); } Response.Cache.SetExpires(expires); Response.Cache.SetETag(etag); } // Add the file data if ((file.PhysicalFile != "") && (file.OutputData == null)) { // If the output data should be cached, return the output data bool cacheOutputData = false; if (file.Avatar != null) { cacheOutputData = CacheHelper.CacheImageAllowed(CurrentSiteName, file.Avatar.AvatarFileSize); } // 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 { Response.Write("<html></html>"); } } else { Response.Write("<html></html>"); } CompleteRequest(); }
protected void Page_Load(object sender, EventArgs e) { string hash = QueryHelper.GetString("hash", string.Empty); string path = QueryHelper.GetString("path", string.Empty); // Validate hash if (ValidationHelper.ValidateHash("?path=" + path, hash, false)) { if (path.StartsWith("~")) { path = Server.MapPath(path); } // Get file content from Amazon S3 IS3ObjectInfo obj = S3ObjectFactory.GetInfo(path); // Check if blob exists if (Provider.ObjectExists(obj)) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); // Set the revalidation SetRevalidation(); DateTime lastModified = S3ObjectInfoProvider.GetStringDateTime(obj.GetMetadata(S3ObjectInfoProvider.LAST_WRITE_TIME)); string etag = "\"" + lastModified.ToString() + "\""; // Client caching - only on the live site if (AllowCache && AllowClientCache && ETagsMatch(etag, lastModified)) { // Set the file time stamps to allow client caching SetTimeStamps(lastModified); RespondNotModified(etag, true); return; } Stream stream = Provider.GetObjectContent(obj); // Set right content type Response.ContentType = MimeTypeHelper.GetMimetype(Path.GetExtension(path)); SetDisposition(Path.GetFileName(path), Path.GetExtension(path)); // Setup Etag property ETag = etag; if (AllowCache) { // Set the file time stamps to allow client caching SetTimeStamps(lastModified); Response.Cache.SetETag(etag); } else { SetCacheability(); } // Send headers Response.Flush(); Byte[] buffer = new Byte[DataHelper.BUFFER_SIZE]; int bytesRead = stream.Read(buffer, 0, DataHelper.BUFFER_SIZE); // Copy data from blob stream to cache while (bytesRead > 0) { // Write the data to the current output stream Response.OutputStream.Write(buffer, 0, bytesRead); // Flush the data to the output Response.Flush(); // Read next part of data bytesRead = stream.Read(buffer, 0, DataHelper.BUFFER_SIZE); } stream.Close(); CompleteRequest(); } else { NotFound(); } } else { URLHelper.Redirect(ResolveUrl("~/CMSMessages/Error.aspx?title=" + ResHelper.GetString("general.badhashtitle") + "&text=" + ResHelper.GetString("general.badhashtext"))); } }