Question

Maximum request length exceeded.

Asked by: dbritt

I've searched and searched on how to fix this problem and the answers do not seem to work for me. (Using .NET 2.0)

Here's what I've tried:
* Page_Error
     - Does not trigger this
* Application_Error
     - Response.Redirect
     - Server.Transfer
     - With and without Server.ClearError both before and after both forms of redirection
*Application_BeginRequest
     - Same steps with Application_Error

Visual Studio steps over the redirects in the debugger but they never seem to work. I read that it's because the page is never actually loaded, but I NEED a way to get a redirection to work. For this particular case, I'd like to redirect them to the upload page they submitted from and tell them that the file is too large. Don't worry about checking the filesize or anything like that for me, I just need to get the redirection part to work correctly. Here is one of several techniques that I tried and was unsuccessful with (despite the description of the problem matching mine EXACTLY): http://www.developer.com/db/print.php/10920_3426051_2

TIA,
Derek

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-01-23 at 11:13:31ID22133562
Tags

length

,

request

Topics

Programming for ASP.NET

,

Microsoft IIS Web Server

Participating Experts
5
Points
500
Comments
63

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Regarding ORA-01000: maximum open cursors exceed
    Hi, Recently i get error: ORA-01000: maximum open cursors exceed when i tried to updating records in many times. Here is the general documentation what i get: Cause: A host language program attempted to open too many cursors. The initialization parameter OPEN_CURSORS det...
  2. ORA-01000: maximum open cursors exceed
    I am doing servlet programming and having this error ORA-01000: maximum open cursors exceed. I have read something about closing the recordset. I have a connection pool to manage the sql connections. My question is by closing the connection "connection.close()", doe...
  3. StringBuilder returns Capacity Exceeds Maximum Capacity…
    In learning to use StringBuilder, <thanks testn>, I realized many of the shell functions that I use can use this class. However, I am still learning. I am using the shell function FindFirstFile to begin a parsing of a particular directory. I used SHGetSpecialFolder t...
  4. checking a session variable in Application_BeginRequest
    Hi guys: I want to look for a session variable in Application_BeginRequest but the problem is that the session variable is not visible in this procedure reason being Application_BeginRequest is processed before Session_Start and I am setting a session variable in Sesson_Star...
  5. URGENT - Lotus Domino - Exceed maximum folder count i…
    We are having a major issue with a Mail db on Domino server that we are unable to open/compact/fixup because of the error "exceed maximum folder count in database". This is one of our major users and they are currently unable to work. Does anyone know how to resol...
  6. Maximum open cursors exceed
    Hi I have a problem with Open Cursor in ORACLE JDBC. While im handling 3 different results sets im getting the following error. java.sql.SQLException: ORA-01000: maximum open cursors exceeded I have tried other solutions by increasing pool size and cursor size. I have to ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: raterusPosted on 2007-01-23 at 12:21:33ID: 18378668

Have you tried a try/catch block in Application_Error that catches the exact exception being raised, which hopefully then you can Response.Redirect to a custom error page?

 

by: dbrittPosted on 2007-01-23 at 12:45:25ID: 18378896

That's not the issue. The redirect is not working. The debugger is showing me that it goes through the line of code to redirect, but it never happens even if I make my Application_Error as simple as:

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        Server.Transfer("test.htm")
    End Sub


Replace Server.Transfer with Response.Redirect, add a Server.ClearError (before or after it), etc...none of that works.

I want to know how to allow the redirect/transfer to be called. It does execute the code because if I put an event logger in there, it writes to the log. It just does not want to get redirected for some reason.

 

by: dbrittPosted on 2007-01-23 at 12:53:08ID: 18378976

Hello btw :)

 

by: dbrittPosted on 2007-01-25 at 05:52:14ID: 18395204

Any other ideas?

 

by: raterusPosted on 2007-01-25 at 06:16:11ID: 18395362

I really don't know what to say..

Read this (It says it can't be done),
http://blogs.inetium.com/blogs/vbullinger/archive/2006/10/09/398.aspx

or Read this (It says it can, with source code to prove it, but I couldn't get it to work...)
http://www.developer.com/db/print.php/10920_3426051_2

Here is one suggestion that may make it more of an IIS issue than ASP.Net,
http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/c388ee023177e5f9/734f58dbb9c8d5d1?lnk=st&q=catch+maximum+request+length&rnum=1#734f58dbb9c8d5d1

Good Luck, wish I had a better report!

 

by: dbrittPosted on 2007-01-25 at 07:04:09ID: 18395832

Thanks for finding those. I already read the first 2 (the links are showing the visited color), but the IIS solution is my next step it seems! I'm going to tinker around with that and see where it takes me. Thanks! :D

 

by: dbrittPosted on 2007-01-29 at 07:49:47ID: 18420133

No luck so far, the metabase fix didn't seem to do anything (was really counting on that one). I can't seem to find a thorough example of implementing the metabase fix for a single file either. What's really weird to me is that the ASPNET Application_Error gets called but that it wont let me send the user elsewhere...

 

by: dbrittPosted on 2007-02-01 at 07:30:25ID: 18444799

Can we get more expert advice please? I must get a solution to detecting and handling too large of uploads.

Thanks

 

by: raterusPosted on 2007-02-01 at 07:41:11ID: 18444899

I guess as a last resort, you could really make the max request length really big, but in your upload page you check the contentlength and spit out an error message.  Obviously not the best.  I threw out your question to some other experts around here, maybe someone else has an idea I don't.

 

by: hujiPosted on 2007-02-01 at 09:17:32ID: 18445814

I guess the solution (if any) is to modify IIS settings, but I'm not sure. If that error you are explaining above is a normal IIS server error (like an HTTP 500 error) then you can send them to an special page, using costum error pages is IIS. I repeat that I'm not sure about what I say.

 

by: Justin_WPosted on 2007-02-01 at 10:02:52ID: 18446179

Raterus is correct. The only way to be able to handle the error in your app's code is to force IIS to allow your app to handle the request, which means increasing the max request length. Otherwise, IIS will just handle the request directly and your app will never even know the request was made.

 

by: dbrittPosted on 2007-02-01 at 12:57:47ID: 18447611

So, how is the Application_Error being fired then? When I step through the code, it uses the handler but just passes over top of my Server.Transfer or Response.Redirect. I can run some code, just not the code I want to run (a redirect).

 

by: raterusPosted on 2007-02-01 at 13:04:01ID: 18447659

 

by: Chinmay_PatelPosted on 2007-02-01 at 20:34:58ID: 18450221

Hi There,

In support of raterus's solution I must send this link, this one is too good, I got this last year when one of our QA guy(my best friend, the only person who could find amazing tricks to break my applications :)) broke my PM Software in fraction of seconds.

URL : http://www.aspnetresources.com/articles/dark_side_of_file_uploads.aspx

Regards,
Chinmay Patel

 

by: dbrittPosted on 2007-02-05 at 07:14:37ID: 18468284

I tried the Application_BeginRequest method (again) with no success there. It gets to the Response.Redirect and then craps out. That's where I'm confused.

 

by: Chinmay_PatelPosted on 2007-02-05 at 10:44:18ID: 18470050

Hi There,

Can you send me the steps you have taken?

Regards,
Chinmay

 

by: dbrittPosted on 2007-02-05 at 12:49:50ID: 18471132

Those ones listed in my first post :)

There just seems to be some bug that wont let me redirect my user and it is VERY frusturating.

 

by: davidlars99Posted on 2007-02-08 at 17:59:56ID: 18498763

It is not doable from .NET. Only possible solution is to increase maxRequestLength as much as you can, and check if uploaded file size > maxRequestLength...

 

by: davidlars99Posted on 2007-02-09 at 08:56:04ID: 18502670

What HTTP status code gets sent down to the client when app encounters this error? You can try to put it in web.config and see...

<customErrors defaultRedirect="~/ErrorPage.aspx" mode="On">
            <error statusCode="500" redirect="~/ErrorPage.aspx" />
            <error statusCode="404" redirect="~/ErrorPage.aspx" />
</customErrors>

 

by: Justin_WPosted on 2007-02-09 at 10:28:50ID: 18503427

OK, based on what your comments above stated you are trying to accomplish and also the limitations of IIS and ASP.NET, the solution described *might* be a satisfactory workaround for you.

1. Create a 2nd ASP.NET application, whose sole purpose is to handle file uploads. This app would be configured so that it has a very large max request length. You could also try putting it in a separate app pool to further isolate it from your other app(s), or even put this app on a separate physical or logical server.

2. Modify your current app so that all file uploads POST to the upload app described in #1.

3. When the upload app gets a posted file, it can do the validation and any necessary error display to the user. When it gets a valid file, you can either have it handle the file completely on its own, or you could try doing a Server.Transfer back to your main app once you are certain that the request length is within the main app's limits.

By doing it this way, you should be able to:

A. Work within the functional limitations of IIS and ASP.NET.

B. limit the negative effects of the large max request length setting to a partially or completely isolated app so that your main app(s) are still safe from DoS, performance issues, etc.

C. Provide end users with customized validation behavior/responses as specified in your comments above.

 

by: Justin_WPosted on 2007-02-09 at 10:55:17ID: 18503623

P.S.
I suspect that what IIS is doing is that it is calling the Application_BeginRequest method after IIS has already sent the HTTP Response back to the client, which is the Redirect won't work even though you can run code in the method. You might want to try adding some diagnostic code in there to check the Response object and it's properties (e.g. Status, StatusCode, etc.) to see whether they are null, and/or what state the Response is in by the time the method is called.

 

by: dbrittPosted on 2007-02-12 at 07:54:09ID: 18515590

Justin, thanks for the suggestion, I'll see if that fits. Regarding the Application_BeginRequest...I was really hoping you were right ;) But it is giving "200 OK" as the Status. (I put a breakpoint on the sub and stepped through any time it was hit...so I know it only gave "OK").

David, I'm too skeptical to believe that Microsoft didn't implement a solution to gracefully handle and/or restrict large file uploads. I may be crazy though ^^ As I found out from my debugger, the status code is 200, so those error pages would never be sent, unfortunately.

 

by: davidlars99Posted on 2007-02-12 at 20:23:50ID: 18520531

I've implemented IHttpModule, and modified actual value of "MaxRequestLength" under the hood object of "HttpRuntime" using reflection, but first you need to check if it really needs to be modified so "OnBeginRequest" of IHttpModule does just that! After modifying it, you need to make sure it is set back to its original value and "Application_EndRequest" of Global.asax takes care of that!

To keep things simple, I used HttpContext object to pass original "MaxRequestLength" value. Here's a humble proof, which really needs further researchnig... :)

http://www.frozendev.com/temp/FileUpload.zip

 

by: davidlars99Posted on 2007-02-12 at 20:25:44ID: 18520539

If you have hard time making this work with ASP.NET 2.0, let me know.

 

by: davidlars99Posted on 2007-02-12 at 20:54:44ID: 18520640

I think in 2.0 it is "_MaxRequestLengthBytes" not "_maxRequestLength"

 

by: davidlars99Posted on 2007-02-13 at 05:39:33ID: 18522420

Here's another one suggested by microsoft - http://support.microsoft.com/kb/910436

 

by: davidlars99Posted on 2007-02-13 at 05:58:26ID: 18522548

Here's better one of all.

public void OnBeginRequest(object o, EventArgs args)
{
      
      HttpApplication app = (HttpApplication)o;
      HttpContext ctx = app.Context;                  

      BindingFlags flags1 = BindingFlags.NonPublic | BindingFlags.Instance;

      
      object typeHandle = ctx.GetConfig("system.web/httpRuntime");
      Type type1 = typeHandle.GetType();
      FieldInfo field = type1.GetField(("_maxRequestLength"), flags1);

      int maxLength = (int)field.GetValue(typeHandle);
      int contentLength = ctx.Request.ContentLength;
      /*
      if (contentLength > maxLength)
      {
            field.SetValue(typeHandle, contentLength);
            ctx.Response.Write(String.Format("{0}{1}", "File is too large!", "<br><br>"));
            ctx.Items["maxLength"] = maxLength;
      }
      */
      if (contentLength > maxLength)
      {
            HttpWorkerRequest wr = (HttpWorkerRequest)(ctx.GetType().GetProperty("WorkerRequest", flags1).GetValue(ctx, null));
            byte[] buffer;
            if (wr.HasEntityBody())
            {
                  int contentlen = Convert.ToInt32(wr.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentLength));
                  buffer = wr.GetPreloadedEntityBody();
                  int received = buffer.Length;
                  int totalrecv = received;
                  if (!wr.IsEntireEntityBodyIsPreloaded())
                  {
                        buffer = new byte[65535];
                        while ((contentlen - totalrecv) >= received)
                        {
                              received = wr.ReadEntityBody(buffer, buffer.Length);
                              totalrecv += received;
                        }
                        received =       wr.ReadEntityBody(buffer, contentlen - totalrecv);
                  }
            }
            ctx.Response.Redirect("http://www.google.com");
      }
}

 

by: Justin_WPosted on 2007-02-13 at 09:36:32ID: 18524253

> Regarding the Application_BeginRequest...I was really hoping you were right ;) But it is giving "200 OK" as the Status.

Well, obviously the browser isn't reacting to the server's response as if it is a "200 OK" response, so I still suspect that the ASP.NET Response object isn't being returned to the client as it would under normal circumstances.  I would check in IIS's request logs and also from the browser and see what Status code(s) they report for the same responses. I suspect that they won't all be 200. :)

However, since you are able to determine the Status code, have you tried _changing_ the status code of the Response (e.g. to 500) within the Application_BeginRequest method to see what affect (if any) that has on the browser's behavior?

 

by: davidlars99Posted on 2007-02-13 at 12:20:49ID: 18525616

Trapping stuff at Application_BeginRequest level is not good, and it's too late. You need to handle it from IHttpHandler...

 

by: davidlars99Posted on 2007-02-13 at 12:44:13ID: 18525874

dbritt - In addition to all of the above suggestion there's one important thing to keep in mind when dealing with such lengthy request, and that is to use asynchronous pages. Do u know how to use ThreadPool with IHttpAsyncHandler interface?

 

by: dbrittPosted on 2007-02-15 at 09:40:17ID: 18542182

I tried the Application_Error approach, no dice. I'm not familiar with any of the interface approaches just yet but am tinkering with the IHttpHandler as we speak. Are those IIS error logs you're talking about (Justin) in the Event Viewer?

 

by: dbrittPosted on 2007-02-15 at 11:05:23ID: 18542908

I just tried a simple IHttpHandler and redirected if the file was too large, again no dice. This is so frusturating :-P

 

by: raterusPosted on 2007-02-15 at 11:16:38ID: 18543002

dbritt,

Have you ever considered using AJAX to perform the upload?  I bet you'd have more control over these weird IIS errors if you don't actually postback the entire page.
http://www.codeproject.com/useritems/AJAXUpload.asp

 

by: dbrittPosted on 2007-02-15 at 12:15:50ID: 18543520

I was actually just testing various AJAX methods. Using ActiveX, Applets, or any other non-native browser options is not an option, unfortunately. I was trying an IFRAME approach just now also with little success. I'm allowed to do anything server-side...just have to figure out what.

 

by: davidlars99Posted on 2007-02-15 at 14:28:21ID: 18544571

> I just tried a simple IHttpHandler and redirected if the file was too large, again no dice.

It works 100% for me. Has anyone else tried using IHttpHandler.

dbritt - I created project and uploaded it to my website as a zip file. Have you actually looked at it?

 

by: davidlars99Posted on 2007-02-15 at 14:30:13ID: 18544584

Sorry, I should have said IHttpModule... Have you tried it?

 

by: davidlars99Posted on 2007-02-15 at 14:31:47ID: 18544597

I don't know why you are reinventing the wheel when I have already gave you a solution..?  :)

 

by: davidlars99Posted on 2007-02-15 at 14:40:46ID: 18544664

Sorry, I think my comments must be pretty confusing so here they are in order:

[solution # 1]
http:Q_22133562.html#a18520531

[solution # 2]
http:Q_22133562.html#a18522548

[something to keep in mind]
http:Q_22133562.html#a18525874

 

by: davidlars99Posted on 2007-02-15 at 14:47:32ID: 18544713

> I bet you'd have more control over these weird IIS errors if you don't actually postback the entire page.

reterus - this is not IIS error, and I can bet my head on it...

 

by: dbrittPosted on 2007-02-19 at 12:44:00ID: 18565894

Hi David,

I looked at your module again and it looks like you increase the allowed maxLength for that request, is that correct? If not, what exactly is the field setting doing?

Also, I am unfamiliar with using the ThreadPool with IHttpAsyncHandler interface as you asked.

 

by: davidlars99Posted on 2007-02-19 at 12:58:39ID: 18566015

--> you increase the allowed maxLength for that request, is that correct?
Yes, it is correct, but it get changed back to its original value when request ends. Now, that was the first solution.

In the second solution you have a full control of entire HttpWorkerRequest. That's why I said it is best of all.

--> Also, I am unfamiliar with using the ThreadPool with IHttpAsyncHandler interface as you asked...

This is not something that I could not describe in two words. You need to visit MSDN and learn it there. You should always consider IHttpAsyncHandler as a second option for those pages, which take more than a couple seconds to display. File upload is the perfect candidate for it.

Some good reading material & code samples:
 
http://msdn2.microsoft.com/en-us/library/ms227433.aspx
http://msdn.microsoft.com/msdnmag/issues/05/10/WickedCode/

 

by: dbrittPosted on 2007-02-20 at 07:18:02ID: 18571089

It seems in both the first and second example...you allow the user to upload the file to the server before any redirection takes place. If that is correct, that defeats the purpose of the original question. The upload should be recognized and _declined_ gracefully.

 

by: davidlars99Posted on 2007-02-20 at 09:35:11ID: 18572235

dbritt - look here -->  http:Q_22133562.html#a18522548

There's lot more going on here than defeating the purpose. In this loop, you get chunks (asynchronously) of data uploaded to the server, and as soon as "received" is more than the value defined in "maxRequestLength" you can redirect users wherever you want.

while ((contentlen - totalrecv) >= received)
{
        received = wr.ReadEntityBody(buffer, buffer.Length);
        totalrecv += received;
}


Do not forget that you can also get the value of native "maxRequestlength" by using some reflection techniques like so:

      HttpApplication app = (HttpApplication)o;
      HttpContext ctx = app.Context;                  

      BindingFlags flags1 = BindingFlags.NonPublic | BindingFlags.Instance;

     
      object typeHandle = ctx.GetConfig("system.web/httpRuntime");
      Type type1 = typeHandle.GetType();
      FieldInfo field = type1.GetField(("_maxRequestLength"), flags1);

      int maxLength = (int)field.GetValue(typeHandle);

"maxLength" is the "maxRequestLength"

 

by: davidlars99Posted on 2007-02-20 at 09:41:08ID: 18572278

> The upload should be recognized and _declined_ gracefully.

And how are you imagining this to happen? There is no good and secure way of doing this because you cannot just get file size unless it is posted to the server.

There is only one ugly way to do this, which is completely unsecured and unprofessional, and that is to use ActiveX.

Of course it'll be fine on local intranet where you can control just about everyones browser settings...  :)

 

by: davidlars99Posted on 2007-02-20 at 09:43:40ID: 18572291

So your final solution would look like this:

while ((contentlen - totalrecv) >= received)
{
        received = wr.ReadEntityBody(buffer, buffer.Length);
        totalrecv += received;
        if (totalrecv >= maxLength)
        {
             Response.Redirect("myerrorpage.aspx");
        }
}


You figure the rest...

 

by: dbrittPosted on 2007-02-21 at 08:15:04ID: 18579515

>> Of course it'll be fine on local intranet where you can control just about everyones browser settings...  :)

Ah yes, I do miss the intranet programming for that reason. ;)

>> And how are you imagining this to happen?

I was hoping to check the context's contentLength and redirect based on that...or some similar check without actually uploading the file itself. Your example has given me an idea though. I think perhaps if I increase the maxRequestLength to the contentLength, then redirect, then reset the maxRequestLength, that _may_ perform as desired...wish me luck. One concern I'd have about that is if OnBeginRequest is being ran in separate threads for separate requests and it sets the maxRequestLength back to default in one thread just after another has increased theirs.

 

by: davidlars99Posted on 2007-02-21 at 09:50:38ID: 18580390

> I think perhaps if I increase the maxRequestLength ... .. .. ....

No, that is not the way you wanna go. I am trying to put you in the right direction, but you seem to be not willing to go the right way.  :)

This is the best way to handle it --> http:Q_22133562.html#a18522548 because you are redirecting the user before asp.net finishes uploading the entire file to the buffer. What if some user tried to upload 50MB file, and you only allow 2MB? With this example, you will be able to determine content length as soon as it exceeds 2MB, where with the other one (changing the maxRequestLength on the fly) you won't be.

> One concern I'd have about that is if OnBeginRequest is being ran in separate threads

I've just told you not to go this way, but if you insist, I'll tell you - Don't worry about it as long as you are doing things in a thread-safe manner.

 

by: raterusPosted on 2007-02-21 at 10:36:42ID: 18580802

Whoa whoa whoa,

Look at this link again davidlars99 has been so nice to post,
http://support.microsoft.com/kb/910436

Microsoft admits it's a problem with IIS 5.1, but it's fixed with IIS 6.0!  I've been doing all my testing on my local PC, IIS 5.1, but when I did a simple redirect in Application_Error like you probably initially tried on IIS 6.0, it worked like a champ!

Go back and check on this, and if you're still running IIS 5.1, do what you need to do to upgrade!

 

by: davidlars99Posted on 2007-02-21 at 10:57:08ID: 18580992

reterus, even if so, my solution beats the all.

I think you agree that checking file size as soon as content is posted to the server is better than wait for the entire thing to upload and then wait for IIS error, and then wait for something else, and wait and wait...  :)

My solution is better even if you are running app under IIS 6. Think about it... And if you use ThreadPool with Async handlers, it makes the whole thing twice better.

 

by: davidlars99Posted on 2007-02-28 at 13:55:54ID: 18629291

Any status updates? We spent so much time figuring this out, and it ends like this?

 

by: dbrittPosted on 2007-03-02 at 06:34:53ID: 18640922

No, sorry, we're near a product release and as this has been worked on I've been assigned several other things. I will try to do more with it Monday. Thanks for your patience :)

 

by: dbrittPosted on 2007-03-15 at 10:22:25ID: 18728752

OK, I've converted your suggested module into VB.NET and trying it now. You have "_maxRequestLength" passed to a GetField, is that intional instead of "maxRequestLength" (no underscore)?

 

by: dbrittPosted on 2007-03-15 at 12:50:10ID: 18729961

David, so far it looks like it's working. Had to make a couple changes to get it to work. Thank you for all the responses. Going to test/optimize it some now and will respond if something is quirky or will award points if it's solid. :)

Thanks again,
Derek

 

by: dbrittPosted on 2007-03-15 at 13:46:22ID: 18730397

I re-read all of our responses, and it's made a lot more sense this time.

I wasn't able to successfully break out of the loop after reading more than the max length though...(which is paramount).

                    While ((contentlen - totalrecv) >= received)
                        received = wr.ReadEntityBody(buffer, buffer.Length)
                        totalrecv += received

                        If totalrecv > maxLength Then
                            wr.CloseConnection()
                            ctx.Response.Redirect("http://www.yahoo.com")
                        End If
                    End While


I tried this with the "wr.CloseConnection()" present and with it not, neither way worked. Were you able to successfully break out? How did you terminate the upload and still be able to redirect?

Thanks.

 

by: davidlars99Posted on 2007-03-16 at 06:24:53ID: 18734513

 

by: dbrittPosted on 2007-03-16 at 07:23:34ID: 18734954

Thank you for your fast response, I really do appreciate it. The example just posted doesn't break out before the entire upload has happened. The only significant change I noticed was a conditional redirect after the file has been _fully_ uploaded

Snippet of your last post:
================================================================
while ((contentLen - totalRecv) >= received)
{
   received = wr.ReadEntityBody(buffer, buffer.Length);
   totalRecv += received;
}
received = wr.ReadEntityBody(buffer, contentLen - totalRecv);
if (totalRecv > maxLength)
{
   ctx.Response.Redirect("http://www.google.com");
}

================================================================

The loop does not stop when my max file size has been reached, it stops when there is less of the header to read than was read in the previous chunk. Knowing how to stop when my max size has been reached is not a problem (that is easy), getting the server to honor the redirect when I break out early IS the problem.

 

by: dbrittPosted on 2007-03-21 at 10:47:44ID: 18765868

David, have you experienced the issue in my last post?

 

by: davidlars99Posted on 2007-03-21 at 14:47:32ID: 18767602

Yes, I did. I was little busy these days, but I did.

From my research, I can tell that it is not possible otherwise. It looks like .NET wants you to flush out everything by calling WorkerProcess.ReadEntityBody(...) method.

If this link doesn't help, then I guess it is the only solution, which is not bed at all... :)

http://support.microsoft.com/kb/910436

 

by: davidlars99Posted on 2007-03-21 at 14:49:21ID: 18767616

Who knows... Maybe I need to do more research to fully understand why the hack .NET works this way...

 

by: dbrittPosted on 2007-03-22 at 08:41:40ID: 18772138

I completely understand being busy. Thanks for returning. :)

If ReadEntityBody is just destroying the uploaded data, that may prove acceptable. I will have to see if that is exactly what happens.

 

by: davidlars99Posted on 2007-03-22 at 14:47:15ID: 18775204

ok. good luck!

 

by: dbrittPosted on 2007-04-11 at 08:30:59ID: 18890470

Thank you everyone for all the replies. Thanks raterus for asking other experts to join the thread. Thanks davidlars99 for continuing to follow this thread. I have accepted that MS does not allow my need on IIS 5.x without uploading the file first; and if it is possible at all that it is not an ASP.Net solution, it would be some esoteric IIS work/hack. The provided alternatives have other positive qualities but do not meet the requirement of declining before reading the file data.

Giving the majority of the points to davidlars99 for being the first to post the official MS statement regarding this issue. Remaining points to raterus and Justin_W for more references to convince me that it's not possible. :)

Cheers!

 

by: davidlars99Posted on 2007-04-11 at 14:47:55ID: 18893736

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...