Connecting Tech Pros Worldwide Help | Site Map

How to intercept error when httpRuntime maxRequestLength is exceded.

moondaddy
Guest
 
Posts: n/a
#1: Nov 18 '05
I have an application where users need to upload images and in my web.config
file I have a setting like this:

<httpRuntime maxRequestLength="512" />

Which restricts image larger than 500k from being uploaded. I'm also using
the HtmlInputFile control to do the uploading. My problem is that when the
user's file size exceeds 512k, the page immediately redirects to the "The
page cannot be displayed" error page which is very confusing. The use will
think that their image is corrupt, or the website has a nasty bug in it.
The way this should be handled is instead of showing the nasty "The page
cannot be displayed" page, show a friendly page telling the user that they
exceeded the file limit and to upload a smaller image.

Is there a way to intercept this and do a redirect? and if not, is there
any other way to handle this elegantly?

--
moondaddy@nospam.com


Paul Glavich [MVP - ASP.NET]
Guest
 
Posts: n/a
#2: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


You should be able to handle this in the Application_Error event in the
Global.asax. The code below just shows some example code

void Application_Error(object sender, EventArgs e)
{
SomeStringVar = .Server.GetLastError.Message();
Server.Transfer("Errors.aspx")
Server.ClearError()
}

You could also have a web.config setting that captures that particular Http
error number and redirects accordingly. Something like :-
<configuration>
<system.web>
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly">
<error statusCode="500"
redirect="InternalError.htm"/>
</customErrors>
</system.web>
</configuration>

You could change (or add another entry) to the '500' for whatever error code
you want.



--
- Paul Glavich
Microsoft MVP - ASP.NET


"moondaddy" <moondaddy@nospam.com> wrote in message
news:O%23lzXrXYEHA.3988@tk2msftngp13.phx.gbl...[color=blue]
> I have an application where users need to upload images and in my[/color]
web.config[color=blue]
> file I have a setting like this:
>
> <httpRuntime maxRequestLength="512" />
>
> Which restricts image larger than 500k from being uploaded. I'm also[/color]
using[color=blue]
> the HtmlInputFile control to do the uploading. My problem is that when[/color]
the[color=blue]
> user's file size exceeds 512k, the page immediately redirects to the "The
> page cannot be displayed" error page which is very confusing. The use[/color]
will[color=blue]
> think that their image is corrupt, or the website has a nasty bug in it.
> The way this should be handled is instead of showing the nasty "The page
> cannot be displayed" page, show a friendly page telling the user that they
> exceeded the file limit and to upload a smaller image.
>
> Is there a way to intercept this and do a redirect? and if not, is there
> any other way to handle this elegantly?
>
> --
> moondaddy@nospam.com
>
>[/color]


moondaddy
Guest
 
Posts: n/a
#3: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


Thanks Paul. I have a few questions/comments. 1) I pasted the error page
text below so you can see the error coming back. There is no error number
so I can't use your example using the web.config file. and 2) I put a break
in the global.asax code behind to step through the code and study the error
message, but the Application_Error event doesnt fire so this must not be an
application error

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim str As String = Server.GetLastError.Message
Log(str , EventLogEntryType.Error)
End Sub

All I know is that the webconfig file's line
<httpRuntime maxRequestLength="512" />
tells asp.net what the constraint is.

Any other ideas on how to trap this error and handle it?



The page cannot be displayed
The page you are looking for is currently unavailable. The Web site
might be experiencing technical difficulties, or you may need to adjust your
browser settings.

--------------------------------------------------------------------------

Please try the following:

a.. Click the Refresh button, or try again later.

b.. If you typed the page address in the Address bar, make sure that
it is spelled correctly.

c.. To check your connection settings, click the Tools menu, and
then click Internet Options. On the Connections tab, click Settings. The
settings should match those provided by your local area network (LAN)
administrator or Internet service provider (ISP).
d.. If your Network Administrator has enabled it, Microsoft Windows
can examine your network and automatically discover network connection
settings.
If you would like Windows to try and discover them,
click Detect Network Settings
e.. Some sites require 128-bit connection security. Click the Help
menu and then click About Internet Explorer to determine what strength
security you have installed.
f.. If you are trying to reach a secure site, make sure your
Security settings can support it. Click the Tools menu, and then click
Internet Options. On the Advanced tab, scroll to the Security section and
check settings for SSL 2.0, SSL 3.0, TLS 1.0, PCT 1.0.
g.. Click the Back button to try another link.



Cannot find server or DNS Error
Internet Explorer






--
moondaddy@nospam.com
"Paul Glavich [MVP - ASP.NET]" <glav@aspalliance.com-NOSPAM> wrote in
message news:uKNwkQZYEHA.2812@TK2MSFTNGP11.phx.gbl...[color=blue]
> You should be able to handle this in the Application_Error event in the
> Global.asax. The code below just shows some example code
>
> void Application_Error(object sender, EventArgs e)
> {
> SomeStringVar = .Server.GetLastError.Message();
> Server.Transfer("Errors.aspx")
> Server.ClearError()
> }
>
> You could also have a web.config setting that captures that particular[/color]
Http[color=blue]
> error number and redirects accordingly. Something like :-
> <configuration>
> <system.web>
> <customErrors defaultRedirect="GenericError.htm"
> mode="RemoteOnly">
> <error statusCode="500"
> redirect="InternalError.htm"/>
> </customErrors>
> </system.web>
> </configuration>
>
> You could change (or add another entry) to the '500' for whatever error[/color]
code[color=blue]
> you want.
>
>
>
> --
> - Paul Glavich
> Microsoft MVP - ASP.NET
>
>
> "moondaddy" <moondaddy@nospam.com> wrote in message
> news:O%23lzXrXYEHA.3988@tk2msftngp13.phx.gbl...[color=green]
> > I have an application where users need to upload images and in my[/color]
> web.config[color=green]
> > file I have a setting like this:
> >
> > <httpRuntime maxRequestLength="512" />
> >
> > Which restricts image larger than 500k from being uploaded. I'm also[/color]
> using[color=green]
> > the HtmlInputFile control to do the uploading. My problem is that when[/color]
> the[color=green]
> > user's file size exceeds 512k, the page immediately redirects to the[/color][/color]
"The[color=blue][color=green]
> > page cannot be displayed" error page which is very confusing. The use[/color]
> will[color=green]
> > think that their image is corrupt, or the website has a nasty bug in it.
> > The way this should be handled is instead of showing the nasty "The page
> > cannot be displayed" page, show a friendly page telling the user that[/color][/color]
they[color=blue][color=green]
> > exceeded the file limit and to upload a smaller image.
> >
> > Is there a way to intercept this and do a redirect? and if not, is[/color][/color]
there[color=blue][color=green]
> > any other way to handle this elegantly?
> >
> > --
> > moondaddy@nospam.com
> >
> >[/color]
>
>[/color]


[MSFT]
Guest
 
Posts: n/a
#4: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


Hello,

I think Paul's suggestion should work. I put following code in
Application_Error, and it worked:

If Request.TotalBytes > MaxValue Then

Server.ClearError()

Response.Clear()

Response.Write "The file is too large"

End If

moondaddy
Guest
 
Posts: n/a
#5: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


Hmmm, I tried your code below and I get the same result as before, I get the
"The page cannot be displayed" page and it seems as though the
Application_Error event isn't firing.

The page is actually a user control sitting on a aspx page and the aspx page
inherits from a base page. I don't know if this would cause the event to
not fire.

I put some breaks in the global.asax and I saw the code execute on the
Application_BeginRequest event, but it clearly isn't hitting the
Application_Error event. I also put a watch on the Response object in the
Application_BeginRequest event and saw the there was no value for
TotalBytes. below is what was listed in the watch window for TotalBytes"

TotalBytes <error: an exception of type: {System.Web.HttpException}
occurred> Integer

Any other ideas?

--
moondaddy@nospam.com
"[MSFT]" <lukezhan@online.microsoft.com> wrote in message
news:gjS9SH$YEHA.1580@cpmsftngxa06.phx.gbl...[color=blue]
> Hello,
>
> I think Paul's suggestion should work. I put following code in
> Application_Error, and it worked:
>
> If Request.TotalBytes > MaxValue Then
>
> Server.ClearError()
>
> Response.Clear()
>
> Response.Write "The file is too large"
>
> End If
>[/color]



moondaddy
Guest
 
Posts: n/a
#6: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


Hmmm, I tried your code below and I get the same result as before, I get the
"The page cannot be displayed" page and it seems as though the
Application_Error event isn't firing.

The page is actually a user control sitting on a aspx page and the aspx page
inherits from a base page. I don't know if this would cause the event to
not fire.

I put some breaks in the global.asax and I saw the code execute on the
Application_BeginRequest event, but it clearly isn't hitting the
Application_Error event. I also put a watch on the Response object in the
Application_BeginRequest event and saw the there was no value for
TotalBytes. below is what was listed in the watch window for TotalBytes"

TotalBytes <error: an exception of type: {System.Web.HttpException}
occurred> Integer

Any other ideas?

--
moondaddy@nospam.com
"[MSFT]" <lukezhan@online.microsoft.com> wrote in message
news:gjS9SH$YEHA.1580@cpmsftngxa06.phx.gbl...[color=blue]
> Hello,
>
> I think Paul's suggestion should work. I put following code in
> Application_Error, and it worked:
>
> If Request.TotalBytes > MaxValue Then
>
> Server.ClearError()
>
> Response.Clear()
>
> Response.Write "The file is too large"
>
> End If
>[/color]


[MSFT]
Guest
 
Posts: n/a
#7: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


Hello,

Here is the web form code I use to test, you may test them on your server
to see if they can work:

<form id="Form1" method="post" enctype="multipart/form-data"
action="WebForm1.aspx" runat="server">

<INPUT id="oFile" type="file" runat="server"
NAME="oFile">

<br>

<asp:button id="btnUpload" type="submit"
text="Upload" runat="server"></asp:button>

<asp:Panel ID="frmConfirmation" Visible="False"
Runat="server">

<asp:Label id="lblUploadResult"
Runat="server"></asp:Label>

</asp:Panel>

</form>





Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpload.Click

Dim strFileName As String

Dim strFilePath As String

Dim strFolder As String



strFolder = "C:\Test\"



'Get the name of the file that is posted.

strFileName = oFile.PostedFile.FileName

strFileName = Path.GetFileName(strFileName)



'Create the directory if it does not exist.

If (Not Directory.Exists(strFolder)) Then

Directory.CreateDirectory(strFolder)

End If



'Save the uploaded file to the server.

strFilePath = strFolder & strFileName



If File.Exists(strFilePath) Then

lblUploadResult.Text = strFileName & " already exists on the
server!"

Else

oFile.PostedFile.SaveAs(strFilePath)

lblUploadResult.Text = strFileName & " has been successfully
uploaded."

End If



'Display the result of the upload.

frmConfirmation.Visible = True



End Sub


The problem may be related the web control you use. Therefore, we may begin
with a basic web form for test.

Luke

Charith
Guest
 
Posts: n/a
#8: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.



hey, this is my suggestion.

so simple.
i think u have to handle this with javascript.

in file upload control, u can check for the file size before send t
the server. if it is large, give an error. if it is in limit, send t
the server.

if u need to get the size from the server, u have to add a hidden fiel
and set the max value from the web config in the page_load event.

tell if it worked.

regards,
Charit


-
Charit
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

ataru
Guest
 
Posts: n/a
#9: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.



If my posted file is bigger than maxRequest in httpRuntime i can trap i
in Application_Error but the redirect to an error page doesn't works an
the process die... I obtain an outpage like classic
Cannot find server....

I didn't find a way to redirect user to an error page...

You suggest to use js client-side to check file size... but j
client-side cannot do it ... can you explain your idea in a block j
code??


Charith wrote:[color=blue]
> *hey, this is my suggestion.
>
> so simple.
> i think u have to handle this with javascript.
>
> in file upload control, u can check for the file size before send t
> the server. if it is large, give an error. if it is in limit, send t
> the server.
>
> if u need to get the size from the server, u have to add a hidde
> field and set the max value from the web config in the page_loa
> event.
>
> tell if it worked.
>
> regards,
> Charith[/color]


-
atar
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Charith
Guest
 
Posts: n/a
#10: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.



just check on this, i didnt try.

[url]http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20573809.html[/url


-
Charit
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Charith
Guest
 
Posts: n/a
#11: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.



[url]http://www.codeproject.com/useritems/FileSelectAndUploadDialog.asp[/url


-
Charit
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

moondaddy
Guest
 
Posts: n/a
#12: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


My pages inherit from a base page so I don't have access to writing
attributes to the form element. You used 2 attributes that I've never used
before: enctype and action. Why are you using these and would they have
any effect on how errors are trapped in the global.asax? I'm still putting
break points on the Application_Error event and also the Global_Error event
but these events aren't executing. Can you offer any more advise on how to
trap this error so I can redirect to a page with a message to the user?
(btw: all of this code is running form a user control which contains all
the content for the page, and the page inherits from a base page)

The solution mentioned Charith in this thread looks like a good solution,
but I'm reluctant to use such JavaScript on the client due to possible
problems with downward browsers. Can anyone recommend some proven
JavaScript for this?

--
moondaddy@nospam.com
"[MSFT]" <lukezhan@online.microsoft.com> wrote in message
news:SesAZxVZEHA.1008@cpmsftngxa06.phx.gbl...[color=blue]
> Hello,
>
> Here is the web form code I use to test, you may test them on your server
> to see if they can work:
>
> <form id="Form1" method="post" enctype="multipart/form-data"
> action="WebForm1.aspx" runat="server">
>
> <INPUT id="oFile" type="file" runat="server"
> NAME="oFile">
>
> <br>
>
> <asp:button id="btnUpload" type="submit"
> text="Upload" runat="server"></asp:button>
>
> <asp:Panel ID="frmConfirmation"[/color]
Visible="False"[color=blue]
> Runat="server">
>
> <asp:Label id="lblUploadResult"
> Runat="server"></asp:Label>
>
> </asp:Panel>
>
> </form>
>
>
>
>
>
> Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnUpload.Click
>
> Dim strFileName As String
>
> Dim strFilePath As String
>
> Dim strFolder As String
>
>
>
> strFolder = "C:\Test\"
>
>
>
> 'Get the name of the file that is posted.
>
> strFileName = oFile.PostedFile.FileName
>
> strFileName = Path.GetFileName(strFileName)
>
>
>
> 'Create the directory if it does not exist.
>
> If (Not Directory.Exists(strFolder)) Then
>
> Directory.CreateDirectory(strFolder)
>
> End If
>
>
>
> 'Save the uploaded file to the server.
>
> strFilePath = strFolder & strFileName
>
>
>
> If File.Exists(strFilePath) Then
>
> lblUploadResult.Text = strFileName & " already exists on the
> server!"
>
> Else
>
> oFile.PostedFile.SaveAs(strFilePath)
>
> lblUploadResult.Text = strFileName & " has been successfully
> uploaded."
>
> End If
>
>
>
> 'Display the result of the upload.
>
> frmConfirmation.Visible = True
>
>
>
> End Sub
>
>
> The problem may be related the web control you use. Therefore, we may[/color]
begin[color=blue]
> with a basic web form for test.
>
> Luke
>[/color]


moondaddy
Guest
 
Posts: n/a
#13: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


I forgot to mention, I also have this setting in my webconfig:
<customErrors mode="Off"/>
for testing. could this have any effect on how the Application_Error event
fires?

--
moondaddy@nospam.com
"moondaddy" <moondaddy@nospam.com> wrote in message
news:%23CDNdYcaEHA.2844@TK2MSFTNGP12.phx.gbl...[color=blue]
> My pages inherit from a base page so I don't have access to writing
> attributes to the form element. You used 2 attributes that I've never[/color]
used[color=blue]
> before: enctype and action. Why are you using these and would they have
> any effect on how errors are trapped in the global.asax? I'm still[/color]
putting[color=blue]
> break points on the Application_Error event and also the Global_Error[/color]
event[color=blue]
> but these events aren't executing. Can you offer any more advise on how[/color]
to[color=blue]
> trap this error so I can redirect to a page with a message to the user?
> (btw: all of this code is running form a user control which contains all
> the content for the page, and the page inherits from a base page)
>
> The solution mentioned Charith in this thread looks like a good solution,
> but I'm reluctant to use such JavaScript on the client due to possible
> problems with downward browsers. Can anyone recommend some proven
> JavaScript for this?
>
> --
> moondaddy@nospam.com
> "[MSFT]" <lukezhan@online.microsoft.com> wrote in message
> news:SesAZxVZEHA.1008@cpmsftngxa06.phx.gbl...[color=green]
> > Hello,
> >
> > Here is the web form code I use to test, you may test them on your[/color][/color]
server[color=blue][color=green]
> > to see if they can work:
> >
> > <form id="Form1" method="post" enctype="multipart/form-data"
> > action="WebForm1.aspx" runat="server">
> >
> > <INPUT id="oFile" type="file" runat="server"
> > NAME="oFile">
> >
> > <br>
> >
> > <asp:button id="btnUpload" type="submit"
> > text="Upload" runat="server"></asp:button>
> >
> > <asp:Panel ID="frmConfirmation"[/color]
> Visible="False"[color=green]
> > Runat="server">
> >
> > <asp:Label id="lblUploadResult"
> > Runat="server"></asp:Label>
> >
> > </asp:Panel>
> >
> > </form>
> >
> >
> >
> >
> >
> > Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles btnUpload.Click
> >
> > Dim strFileName As String
> >
> > Dim strFilePath As String
> >
> > Dim strFolder As String
> >
> >
> >
> > strFolder = "C:\Test\"
> >
> >
> >
> > 'Get the name of the file that is posted.
> >
> > strFileName = oFile.PostedFile.FileName
> >
> > strFileName = Path.GetFileName(strFileName)
> >
> >
> >
> > 'Create the directory if it does not exist.
> >
> > If (Not Directory.Exists(strFolder)) Then
> >
> > Directory.CreateDirectory(strFolder)
> >
> > End If
> >
> >
> >
> > 'Save the uploaded file to the server.
> >
> > strFilePath = strFolder & strFileName
> >
> >
> >
> > If File.Exists(strFilePath) Then
> >
> > lblUploadResult.Text = strFileName & " already exists on the
> > server!"
> >
> > Else
> >
> > oFile.PostedFile.SaveAs(strFilePath)
> >
> > lblUploadResult.Text = strFileName & " has been successfully
> > uploaded."
> >
> > End If
> >
> >
> >
> > 'Display the result of the upload.
> >
> > frmConfirmation.Visible = True
> >
> >
> >
> > End Sub
> >
> >
> > The problem may be related the web control you use. Therefore, we may[/color]
> begin[color=green]
> > with a basic web form for test.
> >
> > Luke
> >[/color]
>
>[/color]


[MSFT]
Guest
 
Posts: n/a
#14: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


This element didn't take any effect on application_error.

Luke

moondaddy
Guest
 
Posts: n/a
#15: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


OK, so where do I go from here?

--
moondaddy@nospam.com
"[MSFT]" <lukezhan@online.microsoft.com> wrote in message
news:0lKFNLjaEHA.2688@cpmsftngxa06.phx.gbl...[color=blue]
> This element didn't take any effect on application_error.
>
> Luke
>[/color]


[MSFT]
Guest
 
Posts: n/a
#16: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


Hello,

Form's Action property sets or retrieves the URL to which the form content
is sent for processing. EncType property sets or retrieves the Multipurpose
Internet Mail Extensions (MIME) encoding for the form.

Would you please post your client code for the form and <INPUT> component,
so I can know what is going on.

Regards,

Luke

[MSFT]
Guest
 
Posts: n/a
#17: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


Hello,

I copied your files to my server and made some changes so that it can run
in the environment. It worked as expected, code in application_error was
executed. The main change I made the files is that I use Windows
authentication. I suggest you may create a new project with Windows
authentication and add this file to the project, to see if it will work.

Luke

moondaddy
Guest
 
Posts: n/a
#18: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


OK I'll try it. Thanks for staying with me on this one. I'll make another
post here when I do to let you know what happened.

--
moondaddy@nospam.com
"[MSFT]" <lukezhan@online.microsoft.com> wrote in message
news:w2zenjVbEHA.3120@cpmsftngxa06.phx.gbl...[color=blue]
> Hello,
>
> I copied your files to my server and made some changes so that it can run
> in the environment. It worked as expected, code in application_error was
> executed. The main change I made the files is that I use Windows
> authentication. I suggest you may create a new project with Windows
> authentication and add this file to the project, to see if it will work.
>
> Luke
>[/color]


[MSFT]
Guest
 
Posts: n/a
#19: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


Thanks. I will look forward to your message.

Luke

Nigil LaVey
Guest
 
Posts: n/a
#20: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


Greetings all...

I had this issue too... did u all manage to come out with a workaround?

regards,
Nigil Chua


R K
Guest
 
Posts: n/a
#21: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.



Check your web.config for Trace element, if the trace element is set to
true in web.config or in the page directive than Application_Error won't
fire.. Give it a try

-RK


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jesse
Guest
 
Posts: n/a
#22: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


Unfortunately this does not work. I have tried redirecting in the
application_error event but for this particular exception, it seems that
asp.net just ignors everything and redirects to the "can't find server or dns
error" page. I have customErrors setup in web.config and that seems to be
ignored as well.

Is there any way we can get microsoft to give us a definitive explanation on
this? Are we basically just stuck displaying an unfriendly page to the user
that doesn't give them any clue about what happened?

Jesse

"Paul Glavich [MVP - ASP.NET]" wrote:
[color=blue]
> You should be able to handle this in the Application_Error event in the
> Global.asax. The code below just shows some example code
>
> void Application_Error(object sender, EventArgs e)
> {
> SomeStringVar = .Server.GetLastError.Message();
> Server.Transfer("Errors.aspx")
> Server.ClearError()
> }
>
> You could also have a web.config setting that captures that particular Http
> error number and redirects accordingly. Something like :-
> <configuration>
> <system.web>
> <customErrors defaultRedirect="GenericError.htm"
> mode="RemoteOnly">
> <error statusCode="500"
> redirect="InternalError.htm"/>
> </customErrors>
> </system.web>
> </configuration>
>
> You could change (or add another entry) to the '500' for whatever error code
> you want.
>
>
>
> --
> - Paul Glavich
> Microsoft MVP - ASP.NET
>
>
> "moondaddy" <moondaddy@nospam.com> wrote in message
> news:O%23lzXrXYEHA.3988@tk2msftngp13.phx.gbl...[color=green]
> > I have an application where users need to upload images and in my[/color]
> web.config[color=green]
> > file I have a setting like this:
> >
> > <httpRuntime maxRequestLength="512" />
> >
> > Which restricts image larger than 500k from being uploaded. I'm also[/color]
> using[color=green]
> > the HtmlInputFile control to do the uploading. My problem is that when[/color]
> the[color=green]
> > user's file size exceeds 512k, the page immediately redirects to the "The
> > page cannot be displayed" error page which is very confusing. The use[/color]
> will[color=green]
> > think that their image is corrupt, or the website has a nasty bug in it.
> > The way this should be handled is instead of showing the nasty "The page
> > cannot be displayed" page, show a friendly page telling the user that they
> > exceeded the file limit and to upload a smaller image.
> >
> > Is there a way to intercept this and do a redirect? and if not, is there
> > any other way to handle this elegantly?
> >
> > --
> > moondaddy@nospam.com
> >
> >[/color]
>
>
>[/color]
Hermit Dave
Guest
 
Posts: n/a
#23: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


its a 2 part thing. if the client browser could not contact the server in
the first place then it will throw its on error in the form of server not
found / dsn error

however as Paul mentioned if the error occurred in your code.. then you
could handle it. sometimes the server is busy serving and doesnt respond...
at that point if you have your custom errors page then it will redirect it

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)

"Jesse" <Jesse@discussions.microsoft.com> wrote in message
news:5BA46BAC-7F8A-4349-8BE2-DE6F4B198CAC@microsoft.com...[color=blue]
> Unfortunately this does not work. I have tried redirecting in the
> application_error event but for this particular exception, it seems that
> asp.net just ignors everything and redirects to the "can't find server or[/color]
dns[color=blue]
> error" page. I have customErrors setup in web.config and that seems to be
> ignored as well.
>
> Is there any way we can get microsoft to give us a definitive explanation[/color]
on[color=blue]
> this? Are we basically just stuck displaying an unfriendly page to the[/color]
user[color=blue]
> that doesn't give them any clue about what happened?
>
> Jesse
>
> "Paul Glavich [MVP - ASP.NET]" wrote:
>[color=green]
> > You should be able to handle this in the Application_Error event in the
> > Global.asax. The code below just shows some example code
> >
> > void Application_Error(object sender, EventArgs e)
> > {
> > SomeStringVar = .Server.GetLastError.Message();
> > Server.Transfer("Errors.aspx")
> > Server.ClearError()
> > }
> >
> > You could also have a web.config setting that captures that particular[/color][/color]
Http[color=blue][color=green]
> > error number and redirects accordingly. Something like :-
> > <configuration>
> > <system.web>
> > <customErrors defaultRedirect="GenericError.htm"
> > mode="RemoteOnly">
> > <error statusCode="500"
> > redirect="InternalError.htm"/>
> > </customErrors>
> > </system.web>
> > </configuration>
> >
> > You could change (or add another entry) to the '500' for whatever error[/color][/color]
code[color=blue][color=green]
> > you want.
> >
> >
> >
> > --
> > - Paul Glavich
> > Microsoft MVP - ASP.NET
> >
> >
> > "moondaddy" <moondaddy@nospam.com> wrote in message
> > news:O%23lzXrXYEHA.3988@tk2msftngp13.phx.gbl...[color=darkred]
> > > I have an application where users need to upload images and in my[/color]
> > web.config[color=darkred]
> > > file I have a setting like this:
> > >
> > > <httpRuntime maxRequestLength="512" />
> > >
> > > Which restricts image larger than 500k from being uploaded. I'm also[/color]
> > using[color=darkred]
> > > the HtmlInputFile control to do the uploading. My problem is that[/color][/color][/color]
when[color=blue][color=green]
> > the[color=darkred]
> > > user's file size exceeds 512k, the page immediately redirects to the[/color][/color][/color]
"The[color=blue][color=green][color=darkred]
> > > page cannot be displayed" error page which is very confusing. The use[/color]
> > will[color=darkred]
> > > think that their image is corrupt, or the website has a nasty bug in[/color][/color][/color]
it.[color=blue][color=green][color=darkred]
> > > The way this should be handled is instead of showing the nasty "The[/color][/color][/color]
page[color=blue][color=green][color=darkred]
> > > cannot be displayed" page, show a friendly page telling the user that[/color][/color][/color]
they[color=blue][color=green][color=darkred]
> > > exceeded the file limit and to upload a smaller image.
> > >
> > > Is there a way to intercept this and do a redirect? and if not, is[/color][/color][/color]
there[color=blue][color=green][color=darkred]
> > > any other way to handle this elegantly?
> > >
> > > --
> > > moondaddy@nospam.com
> > >
> > >[/color]
> >
> >
> >[/color][/color]


Jesse
Guest
 
Posts: n/a
#24: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


I'm going to have to disagree with you. I have full error handling set up on
my site. Error logging in global.asax and custom error setup in web.config.

I even tried to explicity catch the System.Web.HttpException that is thrown
by exceeding the maxRequestLength and then redirecting to a friendly page.
Still no luck there. The only thing that the redirection causes to happen is
that the application_error event now gets fired 3 times. I'll get three
errors logged and still end up on the dns error page.

Go ahead and test this out by stepping through it with the debugger. I'm
getting tired of people saying to catch this problem by checking
httpPostedFile.ContentLength. You can't do it. The code will never be hit
on your page because the runtime throws the exception. So therefore you
would think that you could catch it in global.asax, and you can, but any
redirection will not work. Why? That is the question.

Don't tell me the that the client can't contact the server in these
instances. I'm stepping through it with the debugger man. Why don't you
setup a test and then you will see. You'll get hte dns error after the
server has been hit. I don't know what you mean by "the client browser could
not contact the server". It's obviously hitting the server.

Has microsoft actually setup an examlpe of this? I can send a simple
example solution to anybody that needs proof.



"Hermit Dave" wrote:
[color=blue]
> its a 2 part thing. if the client browser could not contact the server in
> the first place then it will throw its on error in the form of server not
> found / dsn error
>
> however as Paul mentioned if the error occurred in your code.. then you
> could handle it. sometimes the server is busy serving and doesnt respond...
> at that point if you have your custom errors page then it will redirect it
>
> --
>
> Regards,
>
> Hermit Dave
> ()
>
> "Jesse" <Jesse@discussions.microsoft.com> wrote in message
> news:5BA46BAC-7F8A-4349-8BE2-DE6F4B198CAC@microsoft.com...[color=green]
> > Unfortunately this does not work. I have tried redirecting in the
> > application_error event but for this particular exception, it seems that
> > asp.net just ignors everything and redirects to the "can't find server or[/color]
> dns[color=green]
> > error" page. I have customErrors setup in web.config and that seems to be
> > ignored as well.
> >
> > Is there any way we can get microsoft to give us a definitive explanation[/color]
> on[color=green]
> > this? Are we basically just stuck displaying an unfriendly page to the[/color]
> user[color=green]
> > that doesn't give them any clue about what happened?
> >
> > Jesse
> >
> > "Paul Glavich [MVP - ASP.NET]" wrote:
> >[color=darkred]
> > > You should be able to handle this in the Application_Error event in the
> > > Global.asax. The code below just shows some example code
> > >
> > > void Application_Error(object sender, EventArgs e)
> > > {
> > > SomeStringVar = .Server.GetLastError.Message();
> > > Server.Transfer("Errors.aspx")
> > > Server.ClearError()
> > > }
> > >
> > > You could also have a web.config setting that captures that particular[/color][/color]
> Http[color=green][color=darkred]
> > > error number and redirects accordingly. Something like :-
> > > <configuration>
> > > <system.web>
> > > <customErrors defaultRedirect="GenericError.htm"
> > > mode="RemoteOnly">
> > > <error statusCode="500"
> > > redirect="InternalError.htm"/>
> > > </customErrors>
> > > </system.web>
> > > </configuration>
> > >
> > > You could change (or add another entry) to the '500' for whatever error[/color][/color]
> code[color=green][color=darkred]
> > > you want.
> > >
> > >
> > >
> > > --
> > > - Paul Glavich
> > > Microsoft MVP - ASP.NET
> > >
> > >
> > > "moondaddy" <moondaddy@nospam.com> wrote in message
> > > news:O%23lzXrXYEHA.3988@tk2msftngp13.phx.gbl...
> > > > I have an application where users need to upload images and in my
> > > web.config
> > > > file I have a setting like this:
> > > >
> > > > <httpRuntime maxRequestLength="512" />
> > > >
> > > > Which restricts image larger than 500k from being uploaded. I'm also
> > > using
> > > > the HtmlInputFile control to do the uploading. My problem is that[/color][/color]
> when[color=green][color=darkred]
> > > the
> > > > user's file size exceeds 512k, the page immediately redirects to the[/color][/color]
> "The[color=green][color=darkred]
> > > > page cannot be displayed" error page which is very confusing. The use
> > > will
> > > > think that their image is corrupt, or the website has a nasty bug in[/color][/color]
> it.[color=green][color=darkred]
> > > > The way this should be handled is instead of showing the nasty "The[/color][/color]
> page[color=green][color=darkred]
> > > > cannot be displayed" page, show a friendly page telling the user that[/color][/color]
> they[color=green][color=darkred]
> > > > exceeded the file limit and to upload a smaller image.
> > > >
> > > > Is there a way to intercept this and do a redirect? and if not, is[/color][/color]
> there[color=green][color=darkred]
> > > > any other way to handle this elegantly?
> > > >
> > > > --
> > > > moondaddy@nospam.com
> > > >
> > > >
> > >
> > >
> > >[/color][/color]
>
>
>[/color]
Hermit Dave
Guest
 
Posts: n/a
#25: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


okay apologies on my part... i have this problem of not reading the complete
information

i never read about HttpPostedFile.. so didnt know that it was the exception
that was being thrown due to content length being exceeded.
Again - sorry for not reading it fully.

i am copying this contents of a discussion we had on MSWebDev.. it has some
client side javascript and http module which could be helpful.. and it will
also help you understand why you are getting the error and you cant handle
it..

---------------------------

<html>
<head>
<script type="text/javascript">
function CheckAttachment()
{
var fso = new
ActiveXObject("Scripting.FileSystemObject");;
if (fso.GetFile(document.all.FileUpload.value).size[color=blue]
> 4000000)[/color]
{
document.all.ErrorMsg.innerHTML = "File to large!";
return false;
}
return true;
}
</script>
</head>
<body>
<form enctype="multipart/form-data" method="post" onsubmit="return
CheckAttachment()">
File: <input type="file" id="FileUpload" name="FileUpload"
/><br />
<input type="Submit" value="Upload" /><br />
<span id="ErrorMsg" name="ErrorMsg"></span>
</form>
</body>
</html>

----------------------------------------------------------------------------
------

the following code in an HttpModule can read the entire stream and then
redirect to an error page. Using buffering means that the entire file won't
be sucked into memory in a single shot. However if all you want to do is
reject the file for being too large the connection may be tied up for some
considerable time before the user gets the error message. This ties in with
Jos's comments of using a secondary progress window on the client to
potentially recover the broken request scenario:

Apologies for the formatting...

public void BeginRequest(Object source, EventArgs e) {
HttpRequest request = HttpContext.Current.Request;
if (request.ContentLength > 4096000)
{
HttpApplication app = source as HttpApplication;
HtttpContext context = app.Context;
HttpWorkerRequest wr =
(HttpWorkerRequest)(context.GetType().GetProperty
("WorkerRequest", BindingFlags.Instance |
BindingFlags.NonPublic).GetValue(context, 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);
}
}
context.Response.Redirect("~/Error.aspx");
}
}

----------------------------------------------------------------------------

To redirect the client your server has to send back a response. The
redirection is contained in the HTTP headers.

To accept a response the client first has to finish requesting the current
page.

You're rejecting the request itself.

The client isn't going to be expecting a response given that it's not even
finished telling the server what it wants.


----------------------------------------------------------------------------
--

I can understand why the browser displays the message it does on the client
side.

What I can't understand is why I can't trap the request, check the content
length and reject it myself on the server side. By reject I mean redirecting
the user to my own custom error screen if they're attempting to post data
that's deemed too large. After installing an HttpModule and adding my own
BeginRequest handler, checking the content length and attempting a redirect
I would have thought this would prevent the file being uploaded and the
transfer taking place. I thought the BeginRequest was the first call within
the ASP.NET pipeline allowing me to url map, redirect the user, modify the
request etc.


--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Jesse" <Jesse@discussions.microsoft.com> wrote in message
news:B8879A40-C914-4C9A-B9EF-8AEDA1A9E86A@microsoft.com...[color=blue]
> I'm going to have to disagree with you. I have full error handling set up[/color]
on[color=blue]
> my site. Error logging in global.asax and custom error setup in[/color]
web.config.[color=blue]
>
> I even tried to explicity catch the System.Web.HttpException that is[/color]
thrown[color=blue]
> by exceeding the maxRequestLength and then redirecting to a friendly page.
> Still no luck there. The only thing that the redirection causes to happen[/color]
is[color=blue]
> that the application_error event now gets fired 3 times. I'll get three
> errors logged and still end up on the dns error page.
>
> Go ahead and test this out by stepping through it with the debugger. I'm
> getting tired of people saying to catch this problem by checking
> httpPostedFile.ContentLength. You can't do it. The code will never be[/color]
hit[color=blue]
> on your page because the runtime throws the exception. So therefore you
> would think that you could catch it in global.asax, and you can, but any
> redirection will not work. Why? That is the question.
>
> Don't tell me the that the client can't contact the server in these
> instances. I'm stepping through it with the debugger man. Why don't you
> setup a test and then you will see. You'll get hte dns error after the
> server has been hit. I don't know what you mean by "the client browser[/color]
could[color=blue]
> not contact the server". It's obviously hitting the server.
>
> Has microsoft actually setup an examlpe of this? I can send a simple
> example solution to anybody that needs proof.
>
>
>
> "Hermit Dave" wrote:
>[color=green]
> > its a 2 part thing. if the client browser could not contact the server[/color][/color]
in[color=blue][color=green]
> > the first place then it will throw its on error in the form of server[/color][/color]
not[color=blue][color=green]
> > found / dsn error
> >
> > however as Paul mentioned if the error occurred in your code.. then you
> > could handle it. sometimes the server is busy serving and doesnt[/color][/color]
respond...[color=blue][color=green]
> > at that point if you have your custom errors page then it will redirect[/color][/color]
it[color=blue][color=green]
> >
> > --
> >
> > Regards,
> >
> > Hermit Dave
> > ()
> >
> > "Jesse" <Jesse@discussions.microsoft.com> wrote in message
> > news:5BA46BAC-7F8A-4349-8BE2-DE6F4B198CAC@microsoft.com...[color=darkred]
> > > Unfortunately this does not work. I have tried redirecting in the
> > > application_error event but for this particular exception, it seems[/color][/color][/color]
that[color=blue][color=green][color=darkred]
> > > asp.net just ignors everything and redirects to the "can't find server[/color][/color][/color]
or[color=blue][color=green]
> > dns[color=darkred]
> > > error" page. I have customErrors setup in web.config and that seems[/color][/color][/color]
to be[color=blue][color=green][color=darkred]
> > > ignored as well.
> > >
> > > Is there any way we can get microsoft to give us a definitive[/color][/color][/color]
explanation[color=blue][color=green]
> > on[color=darkred]
> > > this? Are we basically just stuck displaying an unfriendly page to[/color][/color][/color]
the[color=blue][color=green]
> > user[color=darkred]
> > > that doesn't give them any clue about what happened?
> > >
> > > Jesse
> > >
> > > "Paul Glavich [MVP - ASP.NET]" wrote:
> > >
> > > > You should be able to handle this in the Application_Error event in[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > > Global.asax. The code below just shows some example code
> > > >
> > > > void Application_Error(object sender, EventArgs e)
> > > > {
> > > > SomeStringVar = .Server.GetLastError.Message();
> > > > Server.Transfer("Errors.aspx")
> > > > Server.ClearError()
> > > > }
> > > >
> > > > You could also have a web.config setting that captures that[/color][/color][/color]
particular[color=blue][color=green]
> > Http[color=darkred]
> > > > error number and redirects accordingly. Something like :-
> > > > <configuration>
> > > > <system.web>
> > > > <customErrors defaultRedirect="GenericError.htm"
> > > > mode="RemoteOnly">
> > > > <error statusCode="500"
> > > > redirect="InternalError.htm"/>
> > > > </customErrors>
> > > > </system.web>
> > > > </configuration>
> > > >
> > > > You could change (or add another entry) to the '500' for whatever[/color][/color][/color]
error[color=blue][color=green]
> > code[color=darkred]
> > > > you want.
> > > >
> > > >
> > > >
> > > > --
> > > > - Paul Glavich
> > > > Microsoft MVP - ASP.NET
> > > >
> > > >
> > > > "moondaddy" <moondaddy@nospam.com> wrote in message
> > > > news:O%23lzXrXYEHA.3988@tk2msftngp13.phx.gbl...
> > > > > I have an application where users need to upload images and in my
> > > > web.config
> > > > > file I have a setting like this:
> > > > >
> > > > > <httpRuntime maxRequestLength="512" />
> > > > >
> > > > > Which restricts image larger than 500k from being uploaded. I'm[/color][/color][/color]
also[color=blue][color=green][color=darkred]
> > > > using
> > > > > the HtmlInputFile control to do the uploading. My problem is that[/color]
> > when[color=darkred]
> > > > the
> > > > > user's file size exceeds 512k, the page immediately redirects to[/color][/color][/color]
the[color=blue][color=green]
> > "The[color=darkred]
> > > > > page cannot be displayed" error page which is very confusing. The[/color][/color][/color]
use[color=blue][color=green][color=darkred]
> > > > will
> > > > > think that their image is corrupt, or the website has a nasty bug[/color][/color][/color]
in[color=blue][color=green]
> > it.[color=darkred]
> > > > > The way this should be handled is instead of showing the nasty[/color][/color][/color]
"The[color=blue][color=green]
> > page[color=darkred]
> > > > > cannot be displayed" page, show a friendly page telling the user[/color][/color][/color]
that[color=blue][color=green]
> > they[color=darkred]
> > > > > exceeded the file limit and to upload a smaller image.
> > > > >
> > > > > Is there a way to intercept this and do a redirect? and if not,[/color][/color][/color]
is[color=blue][color=green]
> > there[color=darkred]
> > > > > any other way to handle this elegantly?
> > > > >
> > > > > --
> > > > > moondaddy@nospam.com
> > > > >
> > > > >
> > > >
> > > >
> > > >[/color]
> >
> >
> >[/color][/color]


Hermit Dave
Guest
 
Posts: n/a
#26: Nov 18 '05

re: How to intercept error when httpRuntime maxRequestLength is exceded.


was it of any help ?

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Hermit Dave" <hermitd.REMOVE@CAPS.AND.DOTS.hotmail.com> wrote in message
news:OrK7a4ejEHA.1464@TK2MSFTNGP10.phx.gbl...[color=blue]
> okay apologies on my part... i have this problem of not reading the[/color]
complete[color=blue]
> information
>
> i never read about HttpPostedFile.. so didnt know that it was the[/color]
exception[color=blue]
> that was being thrown due to content length being exceeded.
> Again - sorry for not reading it fully.
>
> i am copying this contents of a discussion we had on MSWebDev.. it has[/color]
some[color=blue]
> client side javascript and http module which could be helpful.. and it[/color]
will[color=blue]
> also help you understand why you are getting the error and you cant handle
> it..
>
> ---------------------------
>
> <html>
> <head>
> <script type="text/javascript">
> function CheckAttachment()
> {
> var fso = new
> ActiveXObject("Scripting.FileSystemObject");;
> if (fso.GetFile(document.all.FileUpload.value).size[color=green]
> > 4000000)[/color]
> {
> document.all.ErrorMsg.innerHTML = "File to large!";
> return false;
> }
> return true;
> }
> </script>
> </head>
> <body>
> <form enctype="multipart/form-data" method="post" onsubmit="return
> CheckAttachment()">
> File: <input type="file" id="FileUpload" name="FileUpload"
> /><br />
> <input type="Submit" value="Upload" /><br />
> <span id="ErrorMsg" name="ErrorMsg"></span>
> </form>
> </body>
> </html>
>
> --------------------------------------------------------------------------[/color]
--[color=blue]
> ------
>
> the following code in an HttpModule can read the entire stream and then
> redirect to an error page. Using buffering means that the entire file[/color]
won't[color=blue]
> be sucked into memory in a single shot. However if all you want to do is
> reject the file for being too large the connection may be tied up for some
> considerable time before the user gets the error message. This ties in[/color]
with[color=blue]
> Jos's comments of using a secondary progress window on the client to
> potentially recover the broken request scenario:
>
> Apologies for the formatting...
>
> public void BeginRequest(Object source, EventArgs e) {
> HttpRequest request = HttpContext.Current.Request;
> if (request.ContentLength > 4096000)
> {
> HttpApplication app = source as HttpApplication;
> HtttpContext context = app.Context;
> HttpWorkerRequest wr =
> (HttpWorkerRequest)(context.GetType().GetProperty
> ("WorkerRequest", BindingFlags.Instance |
> BindingFlags.NonPublic).GetValue(context, 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);
> }
> }
> context.Response.Redirect("~/Error.aspx");
> }
> }
>
> --------------------------------------------------------------------------[/color]
--[color=blue]
>
> To redirect the client your server has to send back a response. The
> redirection is contained in the HTTP headers.
>
> To accept a response the client first has to finish requesting the current
> page.
>
> You're rejecting the request itself.
>
> The client isn't going to be expecting a response given that it's not even
> finished telling the server what it wants.
>
>
> --------------------------------------------------------------------------[/color]
--[color=blue]
> --
>
> I can understand why the browser displays the message it does on the[/color]
client[color=blue]
> side.
>
> What I can't understand is why I can't trap the request, check the content
> length and reject it myself on the server side. By reject I mean[/color]
redirecting[color=blue]
> the user to my own custom error screen if they're attempting to post data
> that's deemed too large. After installing an HttpModule and adding my own
> BeginRequest handler, checking the content length and attempting a[/color]
redirect[color=blue]
> I would have thought this would prevent the file being uploaded and the
> transfer taking place. I thought the BeginRequest was the first call[/color]
within[color=blue]
> the ASP.NET pipeline allowing me to url map, redirect the user, modify the
> request etc.
>
>
> --
>
> Regards,
>
> Hermit Dave
> (http://hdave.blogspot.com)
> "Jesse" <Jesse@discussions.microsoft.com> wrote in message
> news:B8879A40-C914-4C9A-B9EF-8AEDA1A9E86A@microsoft.com...[color=green]
> > I'm going to have to disagree with you. I have full error handling set[/color][/color]
up[color=blue]
> on[color=green]
> > my site. Error logging in global.asax and custom error setup in[/color]
> web.config.[color=green]
> >
> > I even tried to explicity catch the System.Web.HttpException that is[/color]
> thrown[color=green]
> > by exceeding the maxRequestLength and then redirecting to a friendly[/color][/color]
page.[color=blue][color=green]
> > Still no luck there. The only thing that the redirection causes to[/color][/color]
happen[color=blue]
> is[color=green]
> > that the application_error event now gets fired 3 times. I'll get three
> > errors logged and still end up on the dns error page.
> >
> > Go ahead and test this out by stepping through it with the debugger.[/color][/color]
I'm[color=blue][color=green]
> > getting tired of people saying to catch this problem by checking
> > httpPostedFile.ContentLength. You can't do it. The code will never be[/color]
> hit[color=green]
> > on your page because the runtime throws the exception. So therefore you
> > would think that you could catch it in global.asax, and you can, but any
> > redirection will not work. Why? That is the question.
> >
> > Don't tell me the that the client can't contact the server in these
> > instances. I'm stepping through it with the debugger man. Why don't you
> > setup a test and then you will see. You'll get hte dns error after the
> > server has been hit. I don't know what you mean by "the client browser[/color]
> could[color=green]
> > not contact the server". It's obviously hitting the server.
> >
> > Has microsoft actually setup an examlpe of this? I can send a simple
> > example solution to anybody that needs proof.
> >
> >
> >
> > "Hermit Dave" wrote:
> >[color=darkred]
> > > its a 2 part thing. if the client browser could not contact the server[/color][/color]
> in[color=green][color=darkred]
> > > the first place then it will throw its on error in the form of server[/color][/color]
> not[color=green][color=darkred]
> > > found / dsn error
> > >
> > > however as Paul mentioned if the error occurred in your code.. then[/color][/color][/color]
you[color=blue][color=green][color=darkred]
> > > could handle it. sometimes the server is busy serving and doesnt[/color][/color]
> respond...[color=green][color=darkred]
> > > at that point if you have your custom errors page then it will[/color][/color][/color]
redirect[color=blue]
> it[color=green][color=darkred]
> > >
> > > --
> > >
> > > Regards,
> > >
> > > Hermit Dave
> > > ()
> > >
> > > "Jesse" <Jesse@discussions.microsoft.com> wrote in message
> > > news:5BA46BAC-7F8A-4349-8BE2-DE6F4B198CAC@microsoft.com...
> > > > Unfortunately this does not work. I have tried redirecting in the
> > > > application_error event but for this particular exception, it seems[/color][/color]
> that[color=green][color=darkred]
> > > > asp.net just ignors everything and redirects to the "can't find[/color][/color][/color]
server[color=blue]
> or[color=green][color=darkred]
> > > dns
> > > > error" page. I have customErrors setup in web.config and that seems[/color][/color]
> to be[color=green][color=darkred]
> > > > ignored as well.
> > > >
> > > > Is there any way we can get microsoft to give us a definitive[/color][/color]
> explanation[color=green][color=darkred]
> > > on
> > > > this? Are we basically just stuck displaying an unfriendly page to[/color][/color]
> the[color=green][color=darkred]
> > > user
> > > > that doesn't give them any clue about what happened?
> > > >
> > > > Jesse
> > > >
> > > > "Paul Glavich [MVP - ASP.NET]" wrote:
> > > >
> > > > > You should be able to handle this in the Application_Error event[/color][/color][/color]
in[color=blue]
> the[color=green][color=darkred]
> > > > > Global.asax. The code below just shows some example code
> > > > >
> > > > > void Application_Error(object sender, EventArgs e)
> > > > > {
> > > > > SomeStringVar = .Server.GetLastError.Message();
> > > > > Server.Transfer("Errors.aspx")
> > > > > Server.ClearError()
> > > > > }
> > > > >
> > > > > You could also have a web.config setting that captures that[/color][/color]
> particular[color=green][color=darkred]
> > > Http
> > > > > error number and redirects accordingly. Something like :-
> > > > > <configuration>
> > > > > <system.web>
> > > > > <customErrors defaultRedirect="GenericError.htm"
> > > > > mode="RemoteOnly">
> > > > > <error statusCode="500"
> > > > > redirect="InternalError.htm"/>
> > > > > </customErrors>
> > > > > </system.web>
> > > > > </configuration>
> > > > >
> > > > > You could change (or add another entry) to the '500' for whatever[/color][/color]
> error[color=green][color=darkred]
> > > code
> > > > > you want.
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > - Paul Glavich
> > > > > Microsoft MVP - ASP.NET
> > > > >
> > > > >
> > > > > "moondaddy" <moondaddy@nospam.com> wrote in message
> > > > > news:O%23lzXrXYEHA.3988@tk2msftngp13.phx.gbl...
> > > > > > I have an application where users need to upload images and in[/color][/color][/color]
my[color=blue][color=green][color=darkred]
> > > > > web.config
> > > > > > file I have a setting like this:
> > > > > >
> > > > > > <httpRuntime maxRequestLength="512" />
> > > > > >
> > > > > > Which restricts image larger than 500k from being uploaded. I'm[/color][/color]
> also[color=green][color=darkred]
> > > > > using
> > > > > > the HtmlInputFile control to do the uploading. My problem is[/color][/color][/color]
that[color=blue][color=green][color=darkred]
> > > when
> > > > > the
> > > > > > user's file size exceeds 512k, the page immediately redirects to[/color][/color]
> the[color=green][color=darkred]
> > > "The
> > > > > > page cannot be displayed" error page which is very confusing.[/color][/color][/color]
The[color=blue]
> use[color=green][color=darkred]
> > > > > will
> > > > > > think that their image is corrupt, or the website has a nasty[/color][/color][/color]
bug[color=blue]
> in[color=green][color=darkred]
> > > it.
> > > > > > The way this should be handled is instead of showing the nasty[/color][/color]
> "The[color=green][color=darkred]
> > > page
> > > > > > cannot be displayed" page, show a friendly page telling the user[/color][/color]
> that[color=green][color=darkred]
> > > they
> > > > > > exceeded the file limit and to upload a smaller image.
> > > > > >
> > > > > > Is there a way to intercept this and do a redirect? and if not,[/color][/color]
> is[color=green][color=darkred]
> > > there
> > > > > > any other way to handle this elegantly?
> > > > > >
> > > > > > --
> > > > > > moondaddy@nospam.com
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >[/color][/color]
>
>[/color]


Closed Thread