ASP。NET MVC上传文件超时

时间:2022-12-04 16:37:59

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.

我现在有一个ASP。NET MVC项目有文件上传,如果用户有足够的连接,并且文件大小合理,那么它的工作就很好。

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.

我遇到的问题是,有时一个用户可能有一个56k连接(我不知道他们在这个时代如何使用它),或者正在上传一个更大的文件或两者的某种组合。

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.

我想为普通页面保留一个小的超时(90秒左右),但允许用户上传的操作有一个更大的超时。这只是一个操作,所以我不介意把代码放在这个单独的操作中,而不是一个通用的解决方案中。

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

最终,如果Request.Files会自动增加超时的解决方案。数数>是最好的。

3 个解决方案

#1


8  

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:

我不确定这是否适用于MVC项目,但是您可以尝试在web中创建一个位置。设置并设置上传URL的执行超时。例如:

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

#2


2  

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

您可能需要增加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.

这在子网中是可重写的。配置文件意味着,如果您只想增加上传脚本的超时时间,那么您可以编写一个通用的HTTP处理程序来处理上传,并将其放在自己的子文件夹中,并使用自己的web.config。

#3


0  

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

可能的问题:如果不是因为zero活动而超时,那么它可能与web中的内置大小限制有关。配置httpRuntime部分可以将maxRequestLength=“”添加到大小限制中

#1


8  

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:

我不确定这是否适用于MVC项目,但是您可以尝试在web中创建一个位置。设置并设置上传URL的执行超时。例如:

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

#2


2  

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

您可能需要增加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.

这在子网中是可重写的。配置文件意味着,如果您只想增加上传脚本的超时时间,那么您可以编写一个通用的HTTP处理程序来处理上传,并将其放在自己的子文件夹中,并使用自己的web.config。

#3


0  

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

可能的问题:如果不是因为zero活动而超时,那么它可能与web中的内置大小限制有关。配置httpRuntime部分可以将maxRequestLength=“”添加到大小限制中