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.
Comments
Post a Comment