42

I would like to increase the httpRuntime executionTimeout for a subsection of an ASP.NET MVC application.

In a regular Web App, you could use:

<configuration>
  <location path="UploadPage.aspx">
    <httpRuntime executionTimeout="600"/>
  </location>
</configuration>

However there really is not the idea of "Folders" in ASP.NET MVC, so how would I go about doing this?

Lets assume the ASP.NET MVC path is /Images/Upload with an ImagesController and Upload Action.

KyleMit
  • 30,350
  • 66
  • 462
  • 664
E Rolnicki
  • 1,677
  • 2
  • 17
  • 26

5 Answers5

51

You can include the whole MVC path (controller and action) in the <location> tag's path attribute. Something like this should work:

<location path="Images/Upload">
    <system.web>
        <httpRuntime executionTimeout="600" />
    </system.web>
</location>
Chris Hynes
  • 9,999
  • 2
  • 44
  • 54
  • 2
    I'm still having issues making this work... for clarification: the path is relative to the root of the site, or the app? Also, if there are any values being passed in the url would this fail? (ex: Images/Upload/1) – E Rolnicki Mar 19 '09 at 13:54
  • It's relative to the root of the site, but I think you may be out of luck with the additional values on the url. ASP.NET interprets the path strictly and doesn't allow wildcards. 2 ideas: (a) Use QueryString. – Chris Hynes Mar 20 '09 at 15:38
  • (b) Create an actual Images/Upload folder, and put a web.config inside it. Set path="" to apply to the whole folder. Not sure if ASP.NET will interpret this correctly for MVC apps, but it definitely works for normal ASP.NET apps. – Chris Hynes Mar 20 '09 at 15:39
  • There are conditions when this does not work (for instance a default route for a `ImageController` and a default method of `Upload` would only need a url consisting of `/Image` for an upload would work, but wouldn't get the timeout.) – Erik Philips Apr 09 '14 at 20:46
  • 3
    please note this is ignored completed if debug mode is on http://msdn.microsoft.com/en-us/library/vstudio/e1f13641(v=vs.100).aspx executionTimeout Optional Int32 attribute. Specifies the maximum number of seconds that a request is allowed to execute before being automatically shut down by ASP.NET. This time-out applies only if the debug attribute in the compilation element is False. Therefore, if the debug attribute is True, you do not have to set this attribute to a large value in order to avoid application shutdown while you are debugging. – Nick van Esch Sep 26 '14 at 06:46
  • 2
    Good point. This is a big gotcha because everything works fine in debug mode. Then you go to deploy and it blows up for an unknown reason with poor error messaging. – Chris Hynes Sep 26 '14 at 19:54
  • had to put ~/Images for this to work for me as the path – JsonStatham Jun 03 '15 at 15:33
  • and `HttpContext.Server.ScriptTimeout` ? – Kiquenet Mar 03 '20 at 08:27
8

Chris Hynes solution works! Just be sure to not include ~/ in your path.

This answer details another way - simply set the ScriptTimeout within your action code:

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..
}
Community
  • 1
  • 1
Jarrod Dixon
  • 15,727
  • 9
  • 60
  • 72
  • 6
    I don't think the Server.ScriptTimeout way works. I distinctly remember trying that and not getting it to work. – Jeff Atwood Mar 14 '09 at 09:34
  • 2
    Ah, it was what was checked into our test tier and working before moving back to the web.config version, boss :) – Jarrod Dixon Mar 15 '09 at 02:59
  • It seems that when using ~/, ASP.NET maps it to a physical path. This doesn't happen when using "controller/action"; it's mapped from the app root. Yeah, don't ask me why - I even dug into Reflector to try and figure it out, but it's a pain following config stuff. – Jarrod Dixon Mar 22 '09 at 02:53
  • 4
    This technique doesn't work for me. I need to set the executionTimeout in web.config instead. – Johnny Oshika Jun 11 '10 at 20:04
1

I notice that you are specifically trying to increase the timeout on an upload page. I have had some success with a "chunking" uploader called plupload. A relatively simple MVC actions can be setup to receive the upload's chunks, appending each chunk as it is received. With the small chunks, you will not need to increase the timeout. Of course there might be some browser limitations, but n

http://plupload.com/

oglester
  • 6,605
  • 8
  • 43
  • 63
1

If the action is in the default controller then home/upload does not work, you just put the action name.

KevinUK
  • 5,053
  • 5
  • 33
  • 49
0

Take a look a AsyncController, if you use this, you will have the possibility to set a AsyncTimeout attribute on an action method, so you will be able to timeout a request.

Links that helped me: http://forums.asp.net/p/1564303/3922462.aspx http://dariosantarelli.wordpress.com/2010/10/16/asp-net-mvc-2-handling-timeouts-in-asynchronous-controllers/

jeroen.verhoest
  • 5,173
  • 2
  • 27
  • 27