예제 #1
0
    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))
            {
                Stream stream = Provider.GetObjectContent(obj);

                // Set right content type
                Response.ContentType = MimeTypeHelper.GetMimetype(Path.GetExtension(path));
                SetDisposition(Path.GetFileName(path), Path.GetExtension(path));

                // 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
        {
            URLHelper.Redirect(ResolveUrl("~/CMSMessages/Error.aspx?title=" + ResHelper.GetString("general.badhashtitle") + "&text=" + ResHelper.GetString("general.badhashtext")));
        }
    }
예제 #2
0
    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 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() + "\"";

                // 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, true);
                    return;
                }

                Stream stream = Provider.GetObjectContent(obj);
                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")));
        }
    }