void app_BeginRequest(HttpContext context)
        {
#warning check max length
            //HttpContext context = ((HttpApplication)sender).Context;

            // if (context.Request.ContentLength > 4096)
            //{

            /*IServiceProvider provider = (IServiceProvider)context;
             * HttpWorkerRequest wr = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
             *
             * UploadProcessor p = new UploadProcessor(wr);
             *
             * p.StreamToDisk(provider, Encoding.UTF8, context.Server.MapPath("~/Uploads/"));*/

            IServiceProvider  provider = (IServiceProvider)context;
            HttpWorkerRequest wr       = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));

            FileUploader f = new FileUploader(wr);
            f.ProccessRequest(provider, context.Server.MapPath("~/Uploads/"));
            byte[] data = Encoding.UTF8.GetBytes("ok");
            wr.SendStatus(200, "OK OK OK");
            wr.SendResponseFromMemory(data, data.Length);
            wr.FlushResponse(true);
            wr.EndOfRequest();


            //context.Response.Write("Ok");
            //context.Response.End();



            /* IServiceProvider provider = (IServiceProvider)context;
             * HttpWorkerRequest wr = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
             *
             * int ContentLength;
             * byte[] Buffer;
             * int Received = 0;
             * int TotalReceived = 0;
             * int DefaultBufferLength = 1024;
             * ContentLength = wr.GetTotalEntityBodyLength();
             *
             *
             *
             *
             * using (var ms = new MemoryStream())
             * {
             *  Buffer = wr.GetPreloadedEntityBody();
             *  Received = Buffer.Length;
             *  TotalReceived += Received;
             *  ms.Write(Buffer, 0, Buffer.Length);
             *
             *  if (!wr.IsEntireEntityBodyIsPreloaded())
             *  {
             *      while ((ContentLength - TotalReceived) >= DefaultBufferLength)
             *      {
             *          Buffer = new Byte[DefaultBufferLength];
             *          Received = wr.ReadEntityBody(Buffer, DefaultBufferLength);
             *          TotalReceived += Received;
             *          ms.Write(Buffer, 0, Buffer.Length);
             *          ms.Flush();
             *      }
             *
             *
             *      Buffer = new Byte[DefaultBufferLength];
             *      Received = wr.ReadEntityBody(Buffer, (ContentLength - TotalReceived));
             *      TotalReceived += Received;
             *      ms.Write(Buffer, 0, (ContentLength - TotalReceived));
             *      ms.Flush();
             *  }
             *  ms.Seek(0, SeekOrigin.Begin);
             *  MultipartParser parser = new MultipartParser(ms);
             *  if (parser.Success)
             *  {
             *      using (var fs = new FileStream(context.Server.MapPath("~/Uploads/" + "testfile_ps.txt"), FileMode.Truncate))
             *      {
             *          fs.Write(parser.FileContents, 0, parser.FileContents.Length);
             *          fs.Flush();
             *      }
             *  }
             * }*/



            //  context.Application("Result") = "";
            //    context.Response.Redirect("Upload_Error.aspx?size=" & ContentLength)
            //context.Response.Write("Ok");
            //context.Response.End();
            //}



            /*
             * IServiceProvider provider = (IServiceProvider)context;
             *   HttpWorkerRequest wr = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
             *
             *   int ContentLength;
             *   byte[] Buffer;
             *   int Received = 0;
             *   int TotalReceived = 0;
             *   int DefaultBufferLength = 1024;
             *   ContentLength = wr.GetTotalEntityBodyLength();
             *
             *
             *
             *
             *   using (var fs = new FileStream(context.Server.MapPath("~/Uploads/" + "testfile.txt"), FileMode.Truncate))
             *   {
             *       Buffer = wr.GetPreloadedEntityBody();
             *       Received = Buffer.Length;
             *       TotalReceived += Received;
             *       fs.Write(Buffer, 0, Buffer.Length);
             *
             *       if (!wr.IsEntireEntityBodyIsPreloaded())
             *       {
             *           while ((ContentLength - TotalReceived) >= DefaultBufferLength)
             *           {
             *               Buffer = new Byte[DefaultBufferLength];
             *               Received = wr.ReadEntityBody(Buffer, DefaultBufferLength);
             *               TotalReceived += Received;
             *               fs.Write(Buffer, 0, Buffer.Length);
             *               fs.Flush();
             *           }
             *
             *
             *           Buffer = new Byte[DefaultBufferLength];
             *           Received = wr.ReadEntityBody(Buffer, (ContentLength - TotalReceived));
             *           TotalReceived += Received;
             *           fs.Write(Buffer, 0, (ContentLength - TotalReceived));
             *           fs.Flush();
             *       }
             *
             *
             *   }
             *   //  context.Application("Result") = "";
             *   //    context.Response.Redirect("Upload_Error.aspx?size=" & ContentLength)
             *   context.Response.Write("Ok");
             *   context.Response.End();
             * }*/



            /*  IServiceProvider provider = (IServiceProvider)context;
             * HttpWorkerRequest wr = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
             * FileStream fs = null;
             * // Check if body contains data
             * if (wr.HasEntityBody())
             * {
             *    // get the total body length
             *    int requestLength = wr.GetTotalEntityBodyLength();
             *    // Get the initial bytes loaded
             *    int initialBytes = wr.GetPreloadedEntityBody().Length;
             *
             *    if (!wr.IsEntireEntityBodyIsPreloaded())
             *    {
             *        byte[] buffer = new byte[512000];
             *        //string[] fileName = context.Request.QueryString["fileName"].Split(new char[] { '\\' });
             *        //fs = new FileStream(context.Server.MapPath("~/Uploads/" + fileName[fileName.Length-1]), FileMode.CreateNew);
             *        fs = new FileStream(context.Server.MapPath("~/Uploads/" + "testfile"), FileMode.OpenOrCreate);
             *        // Set the received bytes to initial bytes before start reading
             *        int receivedBytes = initialBytes;
             *        while (requestLength - receivedBytes >= initialBytes)
             *        {
             *            // Read another set of bytes
             *            initialBytes = wr.ReadEntityBody(buffer, buffer.Length);
             *            // Write the chunks to the physical file
             *            fs.Write(buffer, 0, buffer.Length);
             *            // Update the received bytes
             *            receivedBytes += initialBytes;
             *            fs.Flush();
             *        }
             *        initialBytes = wr.ReadEntityBody(buffer, requestLength - receivedBytes);
             *
             *    }
             * }
             * fs.Flush();
             * fs.Close();
             * // context.Response.Redirect("~/");
             * context.Response.Write("zzzz");
             * }*/
        }