I made (with info from this forum) a upload function that uploads in fragments to make it possible to upload big files and show a progress bar. That all works okey, the problem is that i don't want to allow all extensions. What i now have works for good extensions.
When i have a wrong extension i interupt the upload and respond with a simple html text page. The problem is that i get an extra 400 Bad Request after my 200 response. (The one that i want) This results in Internet Explorer is a "Cannot find server or DNS
Error". This is what i picked up as datatraffic with ethereal:
POST /upload.aspx?action=ViewAdd&frame=true&RequestUploadId=true&Upload_id=903ac128-6c10-4884-ab06-e112691aa8b9 HTTP/1.1
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
HTTP/1.1 400 Bad Request
I'm using this code to rewrite the request header, clear the request and output the error:
(source from app.BeginRequest += new EventHandler(this.UploadThread))
HttpApplication app = (HttpApplication) source;
HttpWorkerRequest inWR = GetHttpWorkerRequest(app);
byte[] inData = System.Text.Encoding.Default.GetBytes("header info (in the right format) ");
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic;
Type type = inWR.GetType().BaseType;
type.GetField("_contentAvailLength", bindingFlags).SetValue(inWR, inData.Length);
type.GetField("_contentTotalLength", bindingFlags).SetValue(inWR, inData.Length);
type.GetField("_preloadedContent", bindingFlags).SetValue(inWR, inData);
type.GetField("_preloadedContentRead", bindingFlags).SetValue(inWR, true);
app.Response.Clear();
app.Response.ContentType = "text/html";
app.Response.Cache.SetCacheability(HttpCacheability.NoCache);
app.Response.BufferOutput = false;
app.Response.Write("Upload Error");
app.Response.End();
app.CompleteRequest();
Does anyone know what i'm doing wrong, or maybe a general direction what could be the problem?
Turok-Han
Member
45 Points
9 Posts
400 Bad Request after aborted upload
Jan 05, 2005 11:12 AM|LINK
(source from app.BeginRequest += new EventHandler(this.UploadThread)) HttpApplication app = (HttpApplication) source; HttpWorkerRequest inWR = GetHttpWorkerRequest(app); byte[] inData = System.Text.Encoding.Default.GetBytes("header info (in the right format) "); BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic; Type type = inWR.GetType().BaseType; type.GetField("_contentAvailLength", bindingFlags).SetValue(inWR, inData.Length); type.GetField("_contentTotalLength", bindingFlags).SetValue(inWR, inData.Length); type.GetField("_preloadedContent", bindingFlags).SetValue(inWR, inData); type.GetField("_preloadedContentRead", bindingFlags).SetValue(inWR, true); app.Response.Clear(); app.Response.ContentType = "text/html"; app.Response.Cache.SetCacheability(HttpCacheability.NoCache); app.Response.BufferOutput = false; app.Response.Write("Upload Error"); app.Response.End(); app.CompleteRequest();Does anyone know what i'm doing wrong, or maybe a general direction what could be the problem?