ASP.NET MVC和httpRuntime executionTimeout

E R*_*cki 41 asp.net asp.net-mvc configuration timeout httpruntime

我想增加httpRuntime executionTimeout一个ASP.NET MVC应用程序的子部分.

在常规Web应用程序中,您可以使用:

<configuration>
  <location path="UploadPage.aspx">
    <httpRuntime executionTimeout="600"/>
  </location>
</configuration>
Run Code Online (Sandbox Code Playgroud)

但是,ASP.NET MVC中确实没有"文件夹"的概念,那么我该怎样做呢?

让我们假设ASP.NET MVC路径是/Images/Upload使用ImagesController和Upload Action.

Chr*_*nes 51

您可以在<location>标记的path属性中包含整个MVC路径(控制器和操作).这样的事情应该有效:

<location path="Images/Upload">
    <system.web>
        <httpRuntime executionTimeout="600" />
    </system.web>
</location>
Run Code Online (Sandbox Code Playgroud)

  • 我仍有问题使这项工作...澄清:路径是相对于网站的根目录,还是应用程序?此外,如果在URL中传递了任何值,这会失败吗?(例如:图像/上传/ 1) (2认同)
  • 请注意,如果启用了调试模式,则会忽略此项目http://msdn.microsoft.com/en-us/library/vstudio/e1f13641(v=vs.100).aspx executionTimeout可选的Int32属性.指定在ASP.NET自动关闭之前允许执行请求的最大秒数.仅当编译元素中的debug属性为False时,此超时才适用.因此,如果debug属性为True,则不必将此属性设置为较大的值,以避免在调试时关闭应用程序. (2认同)
  • 好点子.这是一个很大的问题,因为在调试模式下一切正常.然后你去部署,由于错误的消息传递,它会因为一个未知的原因而爆炸. (2认同)

Jar*_*xon 8

Chris Hynes解决方案有效!请务必不要在您的路径中包含〜/.

此答案详述了另一种方法 - 只需ScriptTimeout在您的操作代码中设置:

public ActionResult NoTimeout()
{
    HttpContext.Server.ScriptTimeout = 60 * 10; // Ten minutes..
    System.Threading.Thread.Sleep(1000 * 60 * 5); // Five minutes..
    return Content("NoTimeout complete", "text/plain"); // This will return..
}
Run Code Online (Sandbox Code Playgroud)

  • 我不认为Server.ScriptTimeout方式有效.我清楚地记得尝试过而不是让它发挥作用. (6认同)
  • 这种技术对我不起作用.我需要在web.config中设置executionTimeout. (4认同)
  • 啊,这是检查我们的测试层和工作之前回到web.config版本,老板:) (2认同)