asp.net mvc - Why doesn't my action method time out? -


i have following controllers:

[timeoutfilter] public abstract class basecontroller: controller { }  public class integrationtestcontroller : basecontroller {     [httpget]     public actionresult timeoutseconds()     {         return content(httpcontext.server.scripttimeout.tostring(cultureinfo.invariantculture));     }      [httpget]     public actionresult forcetimeout()     {         var timeoutwindow = timeoutfilter.timeoutseconds;         thread.sleep((timeoutwindow + 5) * 1000);         return content("this should never returned, mwahahaaa!");     } } 

for test scenario use config setting of 5 seconds in timeoutfilter, , know working because when test calls timeoutseconds, correct value of 5, when test calls forcetimeout, http response of 200 , 'never returned' text.

and filter:

public class timeoutfilter : actionfilterattribute {     internal const string timeoutsecondssettingskey = "mvcactiontimeoutseconds";     internal static int timeoutseconds;     public timeoutfilter()     {         timeoutseconds = int.parse(configurationmanager.appsettings[timeoutsecondssettingskey]);     }      public override void onactionexecuting(actionexecutingcontext filtercontext)     {         filtercontext.controller.controllercontext.httpcontext.server.scripttimeout = timeoutseconds;         base.onactionexecuting(filtercontext);     } } 

i not work setting scripttimeout property either, when setting debug="false" in web.config suggested user erik funkenbusch:

<configuration>    <system.web>       <compilation debug="false" targetframework="4.5"/>       ... 

it continued return text "this should never returned" rather timing out during thread.sleep.

it worth noting extended thread.sleep beyond server.scripttimeout default of 110 seconds still returned same text rather timing out.

i instead tried set executiontimeout in web.config:

<configuration>    <system.web>       <httpruntime targetframework="4.5" executiontimeout="5"/>       ... 

if add breakpoint timeoutfilter observe scripttimeout value has been set executiontimeout value web.config. alas, still did not work me (regardless of whether debug="false").

i came across this link scripttimeout , executiontimeout not working similar setup describe. first reply in post describes using debug="false" , mentions timeout have delay of 5 15 seconds. still had no luck when using large thread.sleep value. second reply in article suggests executiontimeout config setting replacement of scripttimeout property (which apparently com interface used in classic asp). reply suggests not possible set specific timeout without using own time-out logic.

further, came across following (more recent) link first reply suggests timeout switched off in mvc. further reply suggests because mvchandler (which selects controller handle httprequest) ihttpasynchandler , may therefore executing request (which point of using async request) therefore internally switches time-out state off (this gather reading link). must work straight asp.net though using scripttimeout seems accepted way in this answer.

the link suggests adding following line allow work (but not in medium trust application):

system.web.httpcontext.current.gettype().getfield("_timeoutstate", system.reflection.bindingflags.instance | system.reflection.bindingflags.nonpublic).setvalue(system.web.httpcontext.current, 1); 

therefore, changing timeoutfilter onactionexecuting() to:

public override void onactionexecuting(actionexecutingcontext filtercontext) {     system.web.httpcontext.current.gettype().getfield("_timeoutstate", system.reflection.bindingflags.instance | system.reflection.bindingflags.nonpublic).setvalue(system.web.httpcontext.current, 1);     base.onactionexecuting(filtercontext); } 

and setting web.config:

<configuration>    <system.web>       <compilation debug="false" targetframework="4.5"/>       <httpruntime targetframework="4.5" executiontimeout="5"/>       ... 

allows time-out work has slight 5 second delay mentioned in first post.

note: using method not allow set scripttimeout property in filter. trying set scripttimeout , override value set in web.config not appear work.


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -