.net - Global regex match timeout works in console application, but not in ASP.NET MVC app -
i'm trying use .net 4.5's new regular expression match timeout, global variant via appdomain.currentdomain.setdata "regex_default_match_timeout" property (the variant whereby pass timespan regex constructor works fine).
when create new console application main method:
static void main(string[] args) { appdomain.currentdomain.setdata("regex_default_match_timeout", timespan.fromseconds(3)); var m = system.text.regularexpressions.regex.match( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "^(x+x+)+y$"); } it works expected: after 3 seconds, throws regexmatchtimeoutexception.
however if create empty mvc 4 app, add homecontroller , action method:
public actionresult index() { appdomain.currentdomain.setdata("regex_default_match_timeout", timespan.fromseconds(3)); var m = system.text.regularexpressions.regex.match( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "^(x+x+)+y$"); return view(); } and visit http://localhost:xxxxx/ no exception thrown , match attempt continues. (if wait long enough, it'll finish, , complain missing view. takes veeery long though.)
calling setdata in global.asax's application_start() instead of within controller action doesn't make timeout happen either.
i guess difference between these 2 samples in console application second line first access regex object , initialize type. in mvc - guess regex class used before index action.
i tried verify behavior simple console application , got same result had in mvc:
var m = system.text.regularexpressions.regex.match( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "x"); appdomain.currentdomain.setdata("regex_default_match_timeout", timespan.fromseconds(3)); var m2 = system.text.regularexpressions.regex.match( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "^(x+x+)+y$"); so, need make sure initialize property before else use it. can specify configuration web.config: http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.defaultregexmatchtimeout.aspx in httpruntime section.
Comments
Post a Comment