开发者

ASP.NET MVC Upload file time out

开发者 https://www.devze.com 2023-02-05 19:28 出处:网络
I currently have an ASP.NET MVC project that has file uploading and it works great开发者_高级运维 if the user has a good enough connection and their file is of a reasonable size.

I currently have an ASP.NET MVC project that has file uploading and it works great开发者_高级运维 if the user has a good enough connection and their file is of a reasonable size.

The problem I'm running into is that sometimes a user might have a 56k connection (how they can live with it in this day and age, I don't know) or are uploading a larger file or some combination of the two.

I'd like to keep a small timeout for normal pages (90 seconds or so), but allow for a larger timeout for actions where a user is uploading. This is just one action, so I don't mind putting code inside just that singular action rather than a generic solution.

Ultimately, a solution that would automatically increase the timeout if Request.Files.Count > 0 would be the best.


I'm not sure if this would work in an MVC project, but you could try creating a location in your web.config and set the execution timeout for just your upload URL. For example:

<location path="YourUrl">
  <system.web>
    <httpRuntime executionTimeout="9001"/>
  </system.web>
</location>


You might need to increase the timeout in web.config:

<httpRuntime executionTimeout="01:00:00" />

Now this is overridable in sub web.config files meaning that if you want to increase the timeout only for the uploading script you could write a generic HTTP handler that will handle the uploads and put it in its own subfolder with its own web.config.


Possible issue: If its not a timeout because of the zero activity, maybe its something to do with the built in size restriction, in the web.config httpRuntime section you could add/increase maxRequestLength="" to your size limit

0

精彩评论

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