c# - Handling page Sessions in helper class -


i have mvc4 web page want show page generation times in milliseconds. code re-use, have created pagehelper static class, want 'starttimer' method, , 'endtimer' method. starttimer returns void, , endtimer returns timespan.

because few pages can used in single 'page hit', putting starttime session[] variable.

public static class pagehelpers {     public static void startpagetimer()     {         var starttime = datetime.now;         session["starttime"] = starttime;      }      public timespan stoptimer()     {         var endtime = datetime.now;         timespan duration = (endtime - datetime.parse(session["starttime"].tostring()));         return duration;     } } 

the problem face, session doesn't seem available in class.... there form of context or something, need pass class?

httpcontext.current.session 

please refer article.

how access asp.net session object inside static function


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -