0

I'm using the following code (asp.net) to show a pdf for the user:

Response.ContentType = "Application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=thePdf.pdf");

//data contains a pdf created with iTextSharp
Response.OutputStream.Write(data, 0, datalength);
Response.End();

Sometimes the users gets an error. I have not been able to recreate the problem but this is what I've seen in my logs and it seems like its always Mozilla 4 or 5 that have the problem:

Error Message: The remote server returned an error: (414) Request-URI Too Large.
Error Source: System
Error Target Site: System.Net.WebResponse GetResponse()


Exception Stack Trace:
----------------------
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.my_doexport_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Server Variables:
-----------------
ALL_HTTP: HTTP_CACHE_CONTROL:no-cache
HTTP_CONNECTION:Keep-Alive
HTTP_ACCEPT:image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
HTTP_ACCEPT_ENCODING:gzip, deflate
HTTP_ACCEPT_LANGUAGE:de
HTTP_COOKIE:ASP.NET_SessionId=xxxxxxxxxxxxa0jo0pxxxxxx; .ASPXFORMSDDDO=XXX436F9868122C336C1E358DBFB1E908F3767FABAEF5338CF62C785ADD6AEA23F8663B413A7C0634DC40F8DCD3B10889CB0FB4CEE18617FB8B1E87C9655AE69C274A1AD0A5F47D95BF8D502F459D05D09A2B0E3691C6737B679F72C6B0XXXXX; __utma=213584726.23687335.1259423588.1259423588.1259423588.1; __utmb=213584726.10.10.1259423588; __utmc=213584726; __utmz=213584726.1259423588.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
HTTP_HOST:www.domain.com
HTTP_REFERER:http://www.domain.com/export.aspx
HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.3; .NET CLR 1.1.4322)

I haven't found a solution to the problem, do you have any ideas on how to solve it?

Martin
  • 1,675
  • 11
  • 34
  • 46
  • How long is the URI, and what do you use it for? – Jørn Schou-Rode Dec 02 '09 at 13:33
  • I don't know how long the URI is, I haven't been able to recreate the problem and the size of pdf vary from time to time. I updated the question with some more info about the error, maybe that can help? – Martin Dec 02 '09 at 14:12

2 Answers2

1

the error message is explicit about Request-URI. the problem doesn't seem to have anything with your response; what is the url used to generate the error?

just somebody
  • 18,602
  • 6
  • 51
  • 60
  • Thanks for your answer! Sorry I'm quite a beginner at asp.net, so it can't be that the pdf is too large? – Martin Dec 02 '09 at 14:16
1

HTTP errors are categorized following way:

1xx - Informational
2xx - Successful 
3xx - Redirection
4xx - Client error
5xx - Server error

Your 414 error must be an error generated by client, not related to your server code. Your browser sent a URL too large to be properly handled by your web server.

So, what is the maximum length of an url?

This link can also be helpful: HTTP 414 Request-URI Too Large and Firefox

Community
  • 1
  • 1
Rubens Farias
  • 57,174
  • 8
  • 131
  • 162
  • Thanks, but is there a solution for this? – Martin Dec 02 '09 at 14:25
  • 1
    You should shorten your URL request; note: problem is at page before, where your user clicks to download your file – Rubens Farias Dec 02 '09 at 14:31
  • But that request is only like this: /Export.aspx?type=1&month=10/1/2009%2012:00:00%20AM&graphics=True&charts=True&comments=True&email=True, that can't be to long or can it? – Martin Dec 02 '09 at 14:46
  • yes, that string have 102 bytes; you should take care when you come closer to 2kbytes – Rubens Farias Dec 02 '09 at 15:04
  • So that isn't the problem then.. hmm.. Do you have any other ideas of what the problem can be? – Martin Dec 02 '09 at 15:23
  • as stated on last link, firefox could be sending cookies through url, please take a look; – Rubens Farias Dec 02 '09 at 16:45
  • Yes, but how can I on the server side be able to get rid of the error? From what I understand in that link, I can't do anything on the server side if it's about cookies. Also wouldn't this problem occur on the rest of site if this was the problem, it only occurs on that specific page? – Martin Dec 02 '09 at 22:12
  • maybe just in this page youre sending many parameters; do you have access to your iis logs inspect pages with 414 errors? – Rubens Farias Dec 03 '09 at 01:11
  • That could be it, but I'm sending almost this long parameters at many pages. No sorry I don't have the logs. Is there any way to prevent this from happening? – Martin Dec 03 '09 at 08:44