Exemplo n.º 1
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            HttpContext  current    = HttpContext.Current;
            HttpRequest  request    = current.Request;
            HttpResponse response   = current.Response;
            string       parameters = request.PathInfo.Substring(1);
            string       dwldhash   = parameters.Split('/')[0];
            string       filename   = parameters.Split('/')[1];

            string   mimeType, dummydisposition, dummyfilename;
            DateTime timestamp;

            byte[] buffer;
            bool   foundFile = RuntimePlatformUtils.GetTemporaryAndroidDownload(dwldhash, out mimeType, out timestamp, out buffer, out dummyfilename, out dummydisposition);

            // all dates are UTC dates
            if (!foundFile || timestamp < DateTime.UtcNow)
            {
                // Note: if seeing strange 404 requests, consider logging more information here
                response.Clear();
                response.Status            = "404 Not Found";
                response.StatusCode        = 404;
                response.StatusDescription = "Not Found";
                response.Write("Bad Request");
                response.End();
            }

            response.Clear();
            response.Status            = "200 OK";
            response.StatusCode        = 200;
            response.StatusDescription = "OK";
            response.ContentType       = mimeType;
            response.AppendHeader("Cache-Control", "private");
            if (filename != String.Empty)
            {
                response.AppendHeader("Content-Disposition", "attachment; filename=" + RuntimePlatformUtils.EscapeFilenameForDownload(filename));
            }

            if (buffer.Length > 0)
            {
                response.BinaryWrite(buffer);
            }

            response.End();
        }