views:

2640

answers:

3

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.

+11  A: 

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
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
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
(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
+6  A: 

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..
}
Jarrod Dixon
I don't think the Server.ScriptTimeout way works. I distinctly remember trying that and not getting it to work.
Jeff Atwood
Ah, it was what was checked into our test tier and working before moving back to the web.config version, boss :)
Jarrod Dixon
why would this not work when using ~/ in the path?
E Rolnicki
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
So, it works or not?
Eduardo Molteni
This technique doesn't work for me. I need to set the executionTimeout in web.config instead.
JohnnyO
+1  A: 

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

KevinUK