3

I am working on a ASP.NET web application that tryies to download some files from a remote server by login the server. While I try to download a file it works fine with small files but a It shows following exception while downloading a file of 750 KB.

enter image description here

I m defining the HTTPRequest Timout = System.Threading.Timeout.Infinite;

I m reading the files from server using this code

byte[] buffer = new byte[32768];
            using (Stream input = getResponse.GetResponseStream())
            {
                using (FileStream output = new FileStream(saveTo1, FileMode.OpenOrCreate))
                {
                    int bytesRead;

                    while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        output.Write(buffer, 0, bytesRead);
                    }
                }
            }

What could possible be creating this problem?

Also When I click on Ignore or Continue It continues the download smoothly further. How can I overcome this problem?

Thanks in Advance. :)

1 Answer 1

15

If you need to handle the timeout exception, you can handle it with javascript. Add this to your page.

<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(requestEndHandler );

// This function will handle the end request event
function requestEndHandler(sender, args) {
   if( args.get_error() ){
      document.getElementById("errorMessageLabel").innerText = 
         args.get_error().description;
       args.set_errorHandled(true);
   }
}

</script>
...

<span id="errorMessageLabel"></span>

Also if you want, you can increase AsyncPostBackTimeOut by sdding AsyncPostBackTimeOut="600"//Time to your script manager.:

<asp:ScriptManager ID="ScriptManager1" runat="server"

AsyncPostBackTimeOut="600" >

</asp:ScriptManager>  
Sign up to request clarification or add additional context in comments.

5 Comments

The way i handled time out is setting its value to -1 that is unlimited.
Do not use unlimited value if not critically important. Having a limited value is a safe bet.
This time value is in miliseconds
No seconds, did the function help?
Wow that worked. Not the function but jus setting the AsyncPostBackTimeOut="60". Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.