I am trying to upload files to a web server using System.Net.WebClient.UploadFile but I keep getting a WebException. Specifically, I am getting 3 errors. I have no idea why I am not getting the same error, but they all seem to be related based on what I found online.
- The request was aborted: The request was canceled.
- Connection closed. Try again.
- An existing connection was forcibly closed by the remote host.
It seems somewhat random (not always the same file, amount of time, or any other pattern that I can figure out). Also This doesn't happen on my work network (the uploads take less than 2 seconds), but does happen from home over a DSL (the uploads take about 2 minutes).
From what I have found online, these errors have something to do with keep-alives. Unfortunately WebClient doesn't provide any way to turn these off (I'm not sure if I would want to anyway since this is a performance feature).
I think it might have something to do with timeouts, but I can't figure out why. The server is ASP.Net MVC and the timeout is set to an hour.
<httpRuntime
maxRequestLength="10024"
executionTimeout="3600"
/><!-- 10024 = 10MB, 3600 = 1hr -->
I'm interested in both ways to fix this problem so it doesn't happen and also recovery techniques (simply making the request again doesn't seem to be effective).
Some background, this is for a WinForms application that uploads photos to the server. The server is an ASP.Net MVC application. The client has worked correctly for a long time but is now failing since I switched it to ASP.Net MVC (it was using classic ASP with SA FileUp). The client side only changed to accomodate the new URLs, other than that it is pretty much the same.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…