开发者

Why is file uploading failing in ASP.Net MVC?

I am uploading files using HttpWebRequest to an ASP.Net MVC application but, for some reason unknown to me, it is failing to upload consistently.

I know the file is good since if you try enough times it does eventually upload and can be viewed on the server just fine. When it fails, neither the server nor client reports any errors directly related to the upload, 开发者_Python百科the upload just stops partway through at a random location and time and my MVC action method is called without the file being loaded (Request.Files.Count == 0).

This only seems to be a problem in our production environment over DSL. The test and development environment works fine and the production environment works fine from in the office (really fast connection to servers) but fails when running it from home over DSL.

As you can see below, the point where it fails is pretty basic.

[Authorize]
[AcceptVerbs(HttpVerbs.Put | HttpVerbs.Post)]
[ValidateInput(false)]
public int UploadScene(int sceneID, int tourID, string name, int number, PhotoType photoType)
{
    SceneInfo scene;
    if (Request.Files.Count < 1) throw new InvalidOperationException("Image file not uploaded.");
    // process file...
}

It seems that it is probably configuration, but I can't figure what it might be. We are running in a cluster (we have 4 web servers) so it might have something to do with that, but I am testing against a single server (I can isolate the machine by name and can verify that it is processing my requests). I have also made sure that it is running in it's own app pool. What else should I check?

We are using IIS6 and .Net 3.5 on the servers.


Have you tried wrapping your form in the proper < form > tag?

<% using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { @enctype = "multipart/form-data" })) { %>


I checked out the event viewer and noticed the app pool was recycling due to a virtual memory check. I turned that off and was able to upload over 20 images without a problem.

Of course this doesn't explain why recycling causes the file upload to fail immediately. I was under the impression that the old pool would continue processing any existing requests until they are complete or the shutdown time limit (we have it setup as 10 minutes in order to handle file uploads).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜