[{"data":1,"prerenderedAt":1211},["ShallowReactive",2],{"blog:2006:extending_httpapplication_with_session_counts_and_uptime_in_c":3,"blogMore-Development":1115,"comments-extending_httpapplication_with_session_counts_and_uptime_in_c":1128},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":11,"tags":12,"excerpt":17,"body":41,"_type":1107,"_id":1108,"_source":1109,"_file":1110,"_stem":1111,"_extension":1112,"url":1113,"wordCount":1114,"minutes":130,"commentCount":212},"/blog/2006/extending_httpapplication_with_session_counts_and_uptime_in_c","2006",false,"en","Extend HttpApplication with session counts and uptime","It’s sometimes useful to know or display how many people are currently using your web application and how long it’s been up for.","2006-06-06T19:43:54+00:00","Development",[13,14,15,16],".NET","ASP.NET","webdev","C#",{"type":18,"children":19},"root",[20,27],{"type":21,"tag":22,"props":23,"children":24},"element","p",{},[25],{"type":26,"value":9},"text",{"type":21,"tag":22,"props":28,"children":29},{},[30,32,39],{"type":26,"value":31},"As web applications normally inherit from ",{"type":21,"tag":33,"props":34,"children":36},"code",{"className":35},[],[37],{"type":26,"value":38},"System.Web.HttpApplication",{"type":26,"value":40}," we can extend this class with a common re-usable class to add the required functionality.",{"type":18,"children":42,"toc":1105},[43,47,57,949,954,991,996,1081,1090,1099],{"type":21,"tag":22,"props":44,"children":45},{},[46],{"type":26,"value":9},{"type":21,"tag":22,"props":48,"children":49},{},[50,51,56],{"type":26,"value":31},{"type":21,"tag":33,"props":52,"children":54},{"className":53},[],[55],{"type":26,"value":38},{"type":26,"value":40},{"type":21,"tag":58,"props":59,"children":64},"pre",{"className":60,"code":61,"language":62,"meta":63,"style":63},"language-csharp shiki shiki-themes everforest-light dracula","public class WebApplication : System.Web.HttpApplication {\n    private static readonlyDateTime pStartedAt = DateTime.Now;\n    private static long pSessionCount = 0;\n\n    public WebApplication() : base() { }\n\n    public override void Init () {\n        base.Init();\n        HookEventHandlers();\n    }\n\n    public static long SessionCount {\n        get { return pSessionCount; }\n    }\n\n    public static DateTime StartedAt {\n        get { return pStartedAt; }\n    }\n    public static TimeSpan Uptime {\n        get { return DateTime.Now.Subtract(pStartedAt); }\n    }\n\n    private void HookEventHandlers () {\n        IHttpModule httpModule = Modules[\"Session\"];\n        if (httpModule is SessionStateModule) {\n            SessionStateModule sessionStateModule = ((SessionStateModule) httpModule);\n            sessionStateModule.Start += new System.EventHandler(SessionStart);\n            sessionStateModule.End += new System.EventHandler(SessionEnd);\n        }\n    }\n\n    private void SessionStart (object sender, EventArgs e) {\n        Interlocked.Increment(ref pSessionCount);\n    }\n\n    private void SessionEnd (object sender, EventArgs e) {\n        Interlocked.Decrement(ref pSessionCount);\n    }\n}\n","csharp","",[65],{"type":21,"tag":33,"props":66,"children":67},{"__ignoreMap":63},[68,128,173,210,220,250,258,286,309,322,331,339,360,384,392,400,422,443,451,473,511,519,527,548,597,626,659,702,740,749,757,765,817,846,854,862,907,932,940],{"type":21,"tag":69,"props":70,"children":73},"span",{"class":71,"line":72},"line",1,[74,80,86,92,98,104,109,114,118,123],{"type":21,"tag":69,"props":75,"children":77},{"style":76},"--shiki-default:#F57D26;--shiki-dark:#FF79C6",[78],{"type":26,"value":79},"public",{"type":21,"tag":69,"props":81,"children":83},{"style":82},"--shiki-default:#F85552;--shiki-dark:#FF79C6",[84],{"type":26,"value":85}," class",{"type":21,"tag":69,"props":87,"children":89},{"style":88},"--shiki-default:#3A94C5;--shiki-dark:#8BE9FD",[90],{"type":26,"value":91}," WebApplication",{"type":21,"tag":69,"props":93,"children":95},{"style":94},"--shiki-default:#5C6A72;--shiki-dark:#F8F8F2",[96],{"type":26,"value":97}," : ",{"type":21,"tag":69,"props":99,"children":101},{"style":100},"--shiki-default:#3A94C5;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[102],{"type":26,"value":103},"System",{"type":21,"tag":69,"props":105,"children":106},{"style":94},[107],{"type":26,"value":108},".",{"type":21,"tag":69,"props":110,"children":111},{"style":100},[112],{"type":26,"value":113},"Web",{"type":21,"tag":69,"props":115,"children":116},{"style":94},[117],{"type":26,"value":108},{"type":21,"tag":69,"props":119,"children":120},{"style":100},[121],{"type":26,"value":122},"HttpApplication",{"type":21,"tag":69,"props":124,"children":125},{"style":94},[126],{"type":26,"value":127}," {\n",{"type":21,"tag":69,"props":129,"children":131},{"class":71,"line":130},2,[132,137,142,147,152,157,162,168],{"type":21,"tag":69,"props":133,"children":134},{"style":76},[135],{"type":26,"value":136},"    private",{"type":21,"tag":69,"props":138,"children":139},{"style":76},[140],{"type":26,"value":141}," static",{"type":21,"tag":69,"props":143,"children":144},{"style":100},[145],{"type":26,"value":146}," readonlyDateTime",{"type":21,"tag":69,"props":148,"children":149},{"style":94},[150],{"type":26,"value":151}," pStartedAt ",{"type":21,"tag":69,"props":153,"children":154},{"style":76},[155],{"type":26,"value":156},"=",{"type":21,"tag":69,"props":158,"children":159},{"style":94},[160],{"type":26,"value":161}," DateTime.",{"type":21,"tag":69,"props":163,"children":165},{"style":164},"--shiki-default:#35A77C;--shiki-dark:#F8F8F2",[166],{"type":26,"value":167},"Now",{"type":21,"tag":69,"props":169,"children":170},{"style":94},[171],{"type":26,"value":172},";\n",{"type":21,"tag":69,"props":174,"children":176},{"class":71,"line":175},3,[177,181,185,191,196,200,206],{"type":21,"tag":69,"props":178,"children":179},{"style":76},[180],{"type":26,"value":136},{"type":21,"tag":69,"props":182,"children":183},{"style":76},[184],{"type":26,"value":141},{"type":21,"tag":69,"props":186,"children":188},{"style":187},"--shiki-default:#3A94C5;--shiki-dark:#FF79C6",[189],{"type":26,"value":190}," long",{"type":21,"tag":69,"props":192,"children":193},{"style":94},[194],{"type":26,"value":195}," pSessionCount ",{"type":21,"tag":69,"props":197,"children":198},{"style":76},[199],{"type":26,"value":156},{"type":21,"tag":69,"props":201,"children":203},{"style":202},"--shiki-default:#DF69BA;--shiki-dark:#BD93F9",[204],{"type":26,"value":205}," 0",{"type":21,"tag":69,"props":207,"children":208},{"style":94},[209],{"type":26,"value":172},{"type":21,"tag":69,"props":211,"children":213},{"class":71,"line":212},4,[214],{"type":21,"tag":69,"props":215,"children":217},{"emptyLinePlaceholder":216},true,[218],{"type":26,"value":219},"\n",{"type":21,"tag":69,"props":221,"children":223},{"class":71,"line":222},5,[224,229,234,239,245],{"type":21,"tag":69,"props":225,"children":226},{"style":76},[227],{"type":26,"value":228},"    public",{"type":21,"tag":69,"props":230,"children":232},{"style":231},"--shiki-default:#8DA101;--shiki-dark:#50FA7B",[233],{"type":26,"value":91},{"type":21,"tag":69,"props":235,"children":236},{"style":94},[237],{"type":26,"value":238},"() : ",{"type":21,"tag":69,"props":240,"children":242},{"style":241},"--shiki-default:#5C6A72;--shiki-default-font-style:inherit;--shiki-dark:#BD93F9;--shiki-dark-font-style:italic",[243],{"type":26,"value":244},"base",{"type":21,"tag":69,"props":246,"children":247},{"style":94},[248],{"type":26,"value":249},"() { }\n",{"type":21,"tag":69,"props":251,"children":253},{"class":71,"line":252},6,[254],{"type":21,"tag":69,"props":255,"children":256},{"emptyLinePlaceholder":216},[257],{"type":26,"value":219},{"type":21,"tag":69,"props":259,"children":261},{"class":71,"line":260},7,[262,266,271,276,281],{"type":21,"tag":69,"props":263,"children":264},{"style":76},[265],{"type":26,"value":228},{"type":21,"tag":69,"props":267,"children":268},{"style":76},[269],{"type":26,"value":270}," override",{"type":21,"tag":69,"props":272,"children":273},{"style":187},[274],{"type":26,"value":275}," void",{"type":21,"tag":69,"props":277,"children":278},{"style":231},[279],{"type":26,"value":280}," Init",{"type":21,"tag":69,"props":282,"children":283},{"style":94},[284],{"type":26,"value":285}," () {\n",{"type":21,"tag":69,"props":287,"children":289},{"class":71,"line":288},8,[290,295,299,304],{"type":21,"tag":69,"props":291,"children":292},{"style":241},[293],{"type":26,"value":294},"        base",{"type":21,"tag":69,"props":296,"children":297},{"style":94},[298],{"type":26,"value":108},{"type":21,"tag":69,"props":300,"children":301},{"style":231},[302],{"type":26,"value":303},"Init",{"type":21,"tag":69,"props":305,"children":306},{"style":94},[307],{"type":26,"value":308},"();\n",{"type":21,"tag":69,"props":310,"children":312},{"class":71,"line":311},9,[313,318],{"type":21,"tag":69,"props":314,"children":315},{"style":231},[316],{"type":26,"value":317},"        HookEventHandlers",{"type":21,"tag":69,"props":319,"children":320},{"style":94},[321],{"type":26,"value":308},{"type":21,"tag":69,"props":323,"children":325},{"class":71,"line":324},10,[326],{"type":21,"tag":69,"props":327,"children":328},{"style":94},[329],{"type":26,"value":330},"    }\n",{"type":21,"tag":69,"props":332,"children":334},{"class":71,"line":333},11,[335],{"type":21,"tag":69,"props":336,"children":337},{"emptyLinePlaceholder":216},[338],{"type":26,"value":219},{"type":21,"tag":69,"props":340,"children":342},{"class":71,"line":341},12,[343,347,351,355],{"type":21,"tag":69,"props":344,"children":345},{"style":76},[346],{"type":26,"value":228},{"type":21,"tag":69,"props":348,"children":349},{"style":76},[350],{"type":26,"value":141},{"type":21,"tag":69,"props":352,"children":353},{"style":187},[354],{"type":26,"value":190},{"type":21,"tag":69,"props":356,"children":357},{"style":94},[358],{"type":26,"value":359}," SessionCount {\n",{"type":21,"tag":69,"props":361,"children":363},{"class":71,"line":362},13,[364,369,374,379],{"type":21,"tag":69,"props":365,"children":366},{"style":187},[367],{"type":26,"value":368},"        get",{"type":21,"tag":69,"props":370,"children":371},{"style":94},[372],{"type":26,"value":373}," { ",{"type":21,"tag":69,"props":375,"children":376},{"style":82},[377],{"type":26,"value":378},"return",{"type":21,"tag":69,"props":380,"children":381},{"style":94},[382],{"type":26,"value":383}," pSessionCount; }\n",{"type":21,"tag":69,"props":385,"children":387},{"class":71,"line":386},14,[388],{"type":21,"tag":69,"props":389,"children":390},{"style":94},[391],{"type":26,"value":330},{"type":21,"tag":69,"props":393,"children":395},{"class":71,"line":394},15,[396],{"type":21,"tag":69,"props":397,"children":398},{"emptyLinePlaceholder":216},[399],{"type":26,"value":219},{"type":21,"tag":69,"props":401,"children":403},{"class":71,"line":402},16,[404,408,412,417],{"type":21,"tag":69,"props":405,"children":406},{"style":76},[407],{"type":26,"value":228},{"type":21,"tag":69,"props":409,"children":410},{"style":76},[411],{"type":26,"value":141},{"type":21,"tag":69,"props":413,"children":414},{"style":100},[415],{"type":26,"value":416}," DateTime",{"type":21,"tag":69,"props":418,"children":419},{"style":94},[420],{"type":26,"value":421}," StartedAt {\n",{"type":21,"tag":69,"props":423,"children":425},{"class":71,"line":424},17,[426,430,434,438],{"type":21,"tag":69,"props":427,"children":428},{"style":187},[429],{"type":26,"value":368},{"type":21,"tag":69,"props":431,"children":432},{"style":94},[433],{"type":26,"value":373},{"type":21,"tag":69,"props":435,"children":436},{"style":82},[437],{"type":26,"value":378},{"type":21,"tag":69,"props":439,"children":440},{"style":94},[441],{"type":26,"value":442}," pStartedAt; }\n",{"type":21,"tag":69,"props":444,"children":446},{"class":71,"line":445},18,[447],{"type":21,"tag":69,"props":448,"children":449},{"style":94},[450],{"type":26,"value":330},{"type":21,"tag":69,"props":452,"children":454},{"class":71,"line":453},19,[455,459,463,468],{"type":21,"tag":69,"props":456,"children":457},{"style":76},[458],{"type":26,"value":228},{"type":21,"tag":69,"props":460,"children":461},{"style":76},[462],{"type":26,"value":141},{"type":21,"tag":69,"props":464,"children":465},{"style":100},[466],{"type":26,"value":467}," TimeSpan",{"type":21,"tag":69,"props":469,"children":470},{"style":94},[471],{"type":26,"value":472}," Uptime {\n",{"type":21,"tag":69,"props":474,"children":476},{"class":71,"line":475},20,[477,481,485,489,493,497,501,506],{"type":21,"tag":69,"props":478,"children":479},{"style":187},[480],{"type":26,"value":368},{"type":21,"tag":69,"props":482,"children":483},{"style":94},[484],{"type":26,"value":373},{"type":21,"tag":69,"props":486,"children":487},{"style":82},[488],{"type":26,"value":378},{"type":21,"tag":69,"props":490,"children":491},{"style":94},[492],{"type":26,"value":161},{"type":21,"tag":69,"props":494,"children":495},{"style":164},[496],{"type":26,"value":167},{"type":21,"tag":69,"props":498,"children":499},{"style":94},[500],{"type":26,"value":108},{"type":21,"tag":69,"props":502,"children":503},{"style":231},[504],{"type":26,"value":505},"Subtract",{"type":21,"tag":69,"props":507,"children":508},{"style":94},[509],{"type":26,"value":510},"(pStartedAt); }\n",{"type":21,"tag":69,"props":512,"children":514},{"class":71,"line":513},21,[515],{"type":21,"tag":69,"props":516,"children":517},{"style":94},[518],{"type":26,"value":330},{"type":21,"tag":69,"props":520,"children":522},{"class":71,"line":521},22,[523],{"type":21,"tag":69,"props":524,"children":525},{"emptyLinePlaceholder":216},[526],{"type":26,"value":219},{"type":21,"tag":69,"props":528,"children":530},{"class":71,"line":529},23,[531,535,539,544],{"type":21,"tag":69,"props":532,"children":533},{"style":76},[534],{"type":26,"value":136},{"type":21,"tag":69,"props":536,"children":537},{"style":187},[538],{"type":26,"value":275},{"type":21,"tag":69,"props":540,"children":541},{"style":231},[542],{"type":26,"value":543}," HookEventHandlers",{"type":21,"tag":69,"props":545,"children":546},{"style":94},[547],{"type":26,"value":285},{"type":21,"tag":69,"props":549,"children":551},{"class":71,"line":550},24,[552,557,562,566,571,576,582,588,592],{"type":21,"tag":69,"props":553,"children":554},{"style":100},[555],{"type":26,"value":556},"        IHttpModule",{"type":21,"tag":69,"props":558,"children":559},{"style":94},[560],{"type":26,"value":561}," httpModule ",{"type":21,"tag":69,"props":563,"children":564},{"style":76},[565],{"type":26,"value":156},{"type":21,"tag":69,"props":567,"children":568},{"style":164},[569],{"type":26,"value":570}," Modules",{"type":21,"tag":69,"props":572,"children":573},{"style":94},[574],{"type":26,"value":575},"[",{"type":21,"tag":69,"props":577,"children":579},{"style":578},"--shiki-default:#8DA101;--shiki-dark:#E9F284",[580],{"type":26,"value":581},"\"",{"type":21,"tag":69,"props":583,"children":585},{"style":584},"--shiki-default:#8DA101;--shiki-dark:#F1FA8C",[586],{"type":26,"value":587},"Session",{"type":21,"tag":69,"props":589,"children":590},{"style":578},[591],{"type":26,"value":581},{"type":21,"tag":69,"props":593,"children":594},{"style":94},[595],{"type":26,"value":596},"];\n",{"type":21,"tag":69,"props":598,"children":600},{"class":71,"line":599},25,[601,606,611,616,621],{"type":21,"tag":69,"props":602,"children":603},{"style":82},[604],{"type":26,"value":605},"        if",{"type":21,"tag":69,"props":607,"children":608},{"style":94},[609],{"type":26,"value":610}," (httpModule ",{"type":21,"tag":69,"props":612,"children":613},{"style":82},[614],{"type":26,"value":615},"is",{"type":21,"tag":69,"props":617,"children":618},{"style":100},[619],{"type":26,"value":620}," SessionStateModule",{"type":21,"tag":69,"props":622,"children":623},{"style":94},[624],{"type":26,"value":625},") {\n",{"type":21,"tag":69,"props":627,"children":629},{"class":71,"line":628},26,[630,635,640,644,649,654],{"type":21,"tag":69,"props":631,"children":632},{"style":100},[633],{"type":26,"value":634},"            SessionStateModule",{"type":21,"tag":69,"props":636,"children":637},{"style":94},[638],{"type":26,"value":639}," sessionStateModule ",{"type":21,"tag":69,"props":641,"children":642},{"style":76},[643],{"type":26,"value":156},{"type":21,"tag":69,"props":645,"children":646},{"style":94},[647],{"type":26,"value":648}," ((",{"type":21,"tag":69,"props":650,"children":651},{"style":100},[652],{"type":26,"value":653},"SessionStateModule",{"type":21,"tag":69,"props":655,"children":656},{"style":94},[657],{"type":26,"value":658},") httpModule);\n",{"type":21,"tag":69,"props":660,"children":662},{"class":71,"line":661},27,[663,668,673,678,683,688,692,697],{"type":21,"tag":69,"props":664,"children":665},{"style":94},[666],{"type":26,"value":667},"            sessionStateModule.",{"type":21,"tag":69,"props":669,"children":670},{"style":164},[671],{"type":26,"value":672},"Start",{"type":21,"tag":69,"props":674,"children":675},{"style":76},[676],{"type":26,"value":677}," +=",{"type":21,"tag":69,"props":679,"children":680},{"style":82},[681],{"type":26,"value":682}," new",{"type":21,"tag":69,"props":684,"children":685},{"style":100},[686],{"type":26,"value":687}," System",{"type":21,"tag":69,"props":689,"children":690},{"style":94},[691],{"type":26,"value":108},{"type":21,"tag":69,"props":693,"children":694},{"style":100},[695],{"type":26,"value":696},"EventHandler",{"type":21,"tag":69,"props":698,"children":699},{"style":94},[700],{"type":26,"value":701},"(SessionStart);\n",{"type":21,"tag":69,"props":703,"children":705},{"class":71,"line":704},28,[706,710,715,719,723,727,731,735],{"type":21,"tag":69,"props":707,"children":708},{"style":94},[709],{"type":26,"value":667},{"type":21,"tag":69,"props":711,"children":712},{"style":164},[713],{"type":26,"value":714},"End",{"type":21,"tag":69,"props":716,"children":717},{"style":76},[718],{"type":26,"value":677},{"type":21,"tag":69,"props":720,"children":721},{"style":82},[722],{"type":26,"value":682},{"type":21,"tag":69,"props":724,"children":725},{"style":100},[726],{"type":26,"value":687},{"type":21,"tag":69,"props":728,"children":729},{"style":94},[730],{"type":26,"value":108},{"type":21,"tag":69,"props":732,"children":733},{"style":100},[734],{"type":26,"value":696},{"type":21,"tag":69,"props":736,"children":737},{"style":94},[738],{"type":26,"value":739},"(SessionEnd);\n",{"type":21,"tag":69,"props":741,"children":743},{"class":71,"line":742},29,[744],{"type":21,"tag":69,"props":745,"children":746},{"style":94},[747],{"type":26,"value":748},"        }\n",{"type":21,"tag":69,"props":750,"children":752},{"class":71,"line":751},30,[753],{"type":21,"tag":69,"props":754,"children":755},{"style":94},[756],{"type":26,"value":330},{"type":21,"tag":69,"props":758,"children":760},{"class":71,"line":759},31,[761],{"type":21,"tag":69,"props":762,"children":763},{"emptyLinePlaceholder":216},[764],{"type":26,"value":219},{"type":21,"tag":69,"props":766,"children":768},{"class":71,"line":767},32,[769,773,777,782,787,792,798,803,808,813],{"type":21,"tag":69,"props":770,"children":771},{"style":76},[772],{"type":26,"value":136},{"type":21,"tag":69,"props":774,"children":775},{"style":187},[776],{"type":26,"value":275},{"type":21,"tag":69,"props":778,"children":779},{"style":231},[780],{"type":26,"value":781}," SessionStart",{"type":21,"tag":69,"props":783,"children":784},{"style":94},[785],{"type":26,"value":786}," (",{"type":21,"tag":69,"props":788,"children":789},{"style":187},[790],{"type":26,"value":791},"object",{"type":21,"tag":69,"props":793,"children":795},{"style":794},"--shiki-default:#5C6A72;--shiki-default-font-style:inherit;--shiki-dark:#FFB86C;--shiki-dark-font-style:italic",[796],{"type":26,"value":797}," sender",{"type":21,"tag":69,"props":799,"children":800},{"style":94},[801],{"type":26,"value":802},", ",{"type":21,"tag":69,"props":804,"children":805},{"style":100},[806],{"type":26,"value":807},"EventArgs",{"type":21,"tag":69,"props":809,"children":810},{"style":794},[811],{"type":26,"value":812}," e",{"type":21,"tag":69,"props":814,"children":815},{"style":94},[816],{"type":26,"value":625},{"type":21,"tag":69,"props":818,"children":820},{"class":71,"line":819},33,[821,826,831,836,841],{"type":21,"tag":69,"props":822,"children":823},{"style":94},[824],{"type":26,"value":825},"        Interlocked.",{"type":21,"tag":69,"props":827,"children":828},{"style":231},[829],{"type":26,"value":830},"Increment",{"type":21,"tag":69,"props":832,"children":833},{"style":94},[834],{"type":26,"value":835},"(",{"type":21,"tag":69,"props":837,"children":838},{"style":76},[839],{"type":26,"value":840},"ref",{"type":21,"tag":69,"props":842,"children":843},{"style":94},[844],{"type":26,"value":845}," pSessionCount);\n",{"type":21,"tag":69,"props":847,"children":849},{"class":71,"line":848},34,[850],{"type":21,"tag":69,"props":851,"children":852},{"style":94},[853],{"type":26,"value":330},{"type":21,"tag":69,"props":855,"children":857},{"class":71,"line":856},35,[858],{"type":21,"tag":69,"props":859,"children":860},{"emptyLinePlaceholder":216},[861],{"type":26,"value":219},{"type":21,"tag":69,"props":863,"children":865},{"class":71,"line":864},36,[866,870,874,879,883,887,891,895,899,903],{"type":21,"tag":69,"props":867,"children":868},{"style":76},[869],{"type":26,"value":136},{"type":21,"tag":69,"props":871,"children":872},{"style":187},[873],{"type":26,"value":275},{"type":21,"tag":69,"props":875,"children":876},{"style":231},[877],{"type":26,"value":878}," SessionEnd",{"type":21,"tag":69,"props":880,"children":881},{"style":94},[882],{"type":26,"value":786},{"type":21,"tag":69,"props":884,"children":885},{"style":187},[886],{"type":26,"value":791},{"type":21,"tag":69,"props":888,"children":889},{"style":794},[890],{"type":26,"value":797},{"type":21,"tag":69,"props":892,"children":893},{"style":94},[894],{"type":26,"value":802},{"type":21,"tag":69,"props":896,"children":897},{"style":100},[898],{"type":26,"value":807},{"type":21,"tag":69,"props":900,"children":901},{"style":794},[902],{"type":26,"value":812},{"type":21,"tag":69,"props":904,"children":905},{"style":94},[906],{"type":26,"value":625},{"type":21,"tag":69,"props":908,"children":910},{"class":71,"line":909},37,[911,915,920,924,928],{"type":21,"tag":69,"props":912,"children":913},{"style":94},[914],{"type":26,"value":825},{"type":21,"tag":69,"props":916,"children":917},{"style":231},[918],{"type":26,"value":919},"Decrement",{"type":21,"tag":69,"props":921,"children":922},{"style":94},[923],{"type":26,"value":835},{"type":21,"tag":69,"props":925,"children":926},{"style":76},[927],{"type":26,"value":840},{"type":21,"tag":69,"props":929,"children":930},{"style":94},[931],{"type":26,"value":845},{"type":21,"tag":69,"props":933,"children":935},{"class":71,"line":934},38,[936],{"type":21,"tag":69,"props":937,"children":938},{"style":94},[939],{"type":26,"value":330},{"type":21,"tag":69,"props":941,"children":943},{"class":71,"line":942},39,[944],{"type":21,"tag":69,"props":945,"children":946},{"style":94},[947],{"type":26,"value":948},"}\n",{"type":21,"tag":22,"props":950,"children":951},{},[952],{"type":26,"value":953},"The next step is to ensure your web application’s class (as defined by global.asax) is of the new WebApplication type. A good approach is to have your own Global.asax.cs file inherit directly from the new WebApplication;",{"type":21,"tag":58,"props":955,"children":957},{"className":60,"code":956,"language":62,"meta":63,"style":63},"public class App : WebApplication { ... }\n",[958],{"type":21,"tag":33,"props":959,"children":960},{"__ignoreMap":63},[961],{"type":21,"tag":69,"props":962,"children":963},{"class":71,"line":72},[964,968,972,977,981,986],{"type":21,"tag":69,"props":965,"children":966},{"style":76},[967],{"type":26,"value":79},{"type":21,"tag":69,"props":969,"children":970},{"style":82},[971],{"type":26,"value":85},{"type":21,"tag":69,"props":973,"children":974},{"style":88},[975],{"type":26,"value":976}," App",{"type":21,"tag":69,"props":978,"children":979},{"style":94},[980],{"type":26,"value":97},{"type":21,"tag":69,"props":982,"children":983},{"style":100},[984],{"type":26,"value":985},"WebApplication",{"type":21,"tag":69,"props":987,"children":988},{"style":94},[989],{"type":26,"value":990}," { ... }\n",{"type":21,"tag":22,"props":992,"children":993},{},[994],{"type":26,"value":995},"Now those sessions and uptime are being tracked how do you get at them?",{"type":21,"tag":58,"props":997,"children":999},{"className":60,"code":998,"language":62,"meta":63,"style":63},"lblCurrentSessions.Text = WebApplication.SessionCount.ToString();\nlblUptime.Text = WebApplication.Uptime.ToString();\n",[1000],{"type":21,"tag":33,"props":1001,"children":1002},{"__ignoreMap":63},[1003,1044],{"type":21,"tag":69,"props":1004,"children":1005},{"class":71,"line":72},[1006,1011,1016,1021,1026,1031,1035,1040],{"type":21,"tag":69,"props":1007,"children":1008},{"style":94},[1009],{"type":26,"value":1010},"lblCurrentSessions.",{"type":21,"tag":69,"props":1012,"children":1013},{"style":164},[1014],{"type":26,"value":1015},"Text",{"type":21,"tag":69,"props":1017,"children":1018},{"style":76},[1019],{"type":26,"value":1020}," =",{"type":21,"tag":69,"props":1022,"children":1023},{"style":94},[1024],{"type":26,"value":1025}," WebApplication.",{"type":21,"tag":69,"props":1027,"children":1028},{"style":164},[1029],{"type":26,"value":1030},"SessionCount",{"type":21,"tag":69,"props":1032,"children":1033},{"style":94},[1034],{"type":26,"value":108},{"type":21,"tag":69,"props":1036,"children":1037},{"style":231},[1038],{"type":26,"value":1039},"ToString",{"type":21,"tag":69,"props":1041,"children":1042},{"style":94},[1043],{"type":26,"value":308},{"type":21,"tag":69,"props":1045,"children":1046},{"class":71,"line":130},[1047,1052,1056,1060,1064,1069,1073,1077],{"type":21,"tag":69,"props":1048,"children":1049},{"style":94},[1050],{"type":26,"value":1051},"lblUptime.",{"type":21,"tag":69,"props":1053,"children":1054},{"style":164},[1055],{"type":26,"value":1015},{"type":21,"tag":69,"props":1057,"children":1058},{"style":76},[1059],{"type":26,"value":1020},{"type":21,"tag":69,"props":1061,"children":1062},{"style":94},[1063],{"type":26,"value":1025},{"type":21,"tag":69,"props":1065,"children":1066},{"style":164},[1067],{"type":26,"value":1068},"Uptime",{"type":21,"tag":69,"props":1070,"children":1071},{"style":94},[1072],{"type":26,"value":108},{"type":21,"tag":69,"props":1074,"children":1075},{"style":231},[1076],{"type":26,"value":1039},{"type":21,"tag":69,"props":1078,"children":1079},{"style":94},[1080],{"type":26,"value":308},{"type":21,"tag":1082,"props":1083,"children":1084},"blockquote",{},[1085],{"type":21,"tag":22,"props":1086,"children":1087},{},[1088],{"type":26,"value":1089},"This approach is only suitable for sites operating on a single web server.",{"type":21,"tag":22,"props":1091,"children":1092},{},[1093],{"type":21,"tag":1094,"props":1095,"children":1096},"em",{},[1097],{"type":26,"value":1098},"[)amien",{"type":21,"tag":1100,"props":1101,"children":1102},"style",{},[1103],{"type":26,"value":1104},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":63,"searchDepth":130,"depth":130,"links":1106},[],"markdown","content:blog:2006:extending_httpapplication_with_session_counts_and_uptime_in_c.md","content","blog/2006/extending_httpapplication_with_session_counts_and_uptime_in_c.md","blog/2006/extending_httpapplication_with_session_counts_and_uptime_in_c","md","/blog/2006/extending_httpapplication_with_session_counts_and_uptime_in_c/",338,[1116,1120,1124],{"title":1117,"date":1118,"url":1119},"HTML5 Video Cheatsheet: Optimizing videos for the web","2025-12-05T00:00:00Z","/blog/2025/html5-video-cheatsheet/",{"title":1121,"date":1122,"url":1123},"Transactions in the MongoDB EF Core Provider","2025-10-25","/blog/2025/mongodb-explicit-transactions/",{"title":1125,"date":1126,"url":1127},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","/blog/2025/mongodb-queryable-encryption/",[1129,1151,1172,1189],{"_path":1130,"_dir":1131,"_draft":6,"_partial":6,"_locale":7,"title":1132,"description":1133,"id":1134,"name":1135,"email":1136,"avatar":1137,"url":1138,"date":1139,"body":1140,"_type":1107,"_id":1148,"_source":1109,"_file":1149,"_stem":1150,"_extension":1112},"/comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1503","extending_httpapplication_with_session_counts_and_uptime_in_c","1503","Java's main problem is the lack of simple out of the box complete frameworks for things like web development - there are lots of really great libs and tools out there (Struts, JSF, XDoclet) but you have to know where to get them and assemble them yourself - it's strongly decoupled and flexible approach is its own worst enemy, there's no turnkey version. Trust me, once you get a platform going it's as productive as .Net but it takes time to build it - impractical on a course (I know, the Java I did in my degree is nothing like what I do for a living). They've gone some way to making this better in v5 with Annotations, but it's still the major reason developers prefer .Net on first sight IMO, .Net hands you more stuff on a plate so it's quicker to get going.",1503,"Steve","steve@stevestreeting.com","https://www.gravatar.com/avatar/fbe8cc9ac5bc8797382e01e10f5f8e33?r=pg&d=retro","https://www.stevestreeting.com","2006-06-08T04:25:23",{"type":18,"children":1141,"toc":1146},[1142],{"type":21,"tag":22,"props":1143,"children":1144},{},[1145],{"type":26,"value":1133},{"title":63,"searchDepth":130,"depth":130,"links":1147},[],"content:comments:extending_httpapplication_with_session_counts_and_uptime_in_c:1503.md","comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1503.md","comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1503",{"_path":1152,"_dir":1131,"_draft":6,"_partial":6,"_locale":7,"title":1153,"description":1154,"id":1155,"name":1156,"email":1157,"avatar":1158,"url":1159,"date":1160,"body":1161,"_type":1107,"_id":1169,"_source":1109,"_file":1170,"_stem":1171,"_extension":1112},"/comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1502","1502","Having written a mini eBay for my degree in Java + JSP I can much say I prefer the .NET approach to web development.",1502,"Damien Guard","damien@envytech.co.uk","https://www.gravatar.com/avatar/dc72963e7279d34c85ed4c0b731ce5a9?r=pg&d=retro","https://damieng.com/","2006-06-07T14:07:49",{"type":18,"children":1162,"toc":1167},[1163],{"type":21,"tag":22,"props":1164,"children":1165},{},[1166],{"type":26,"value":1154},{"title":63,"searchDepth":130,"depth":130,"links":1168},[],"content:comments:extending_httpapplication_with_session_counts_and_uptime_in_c:1502.md","comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1502.md","comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1502",{"_path":1173,"_dir":1131,"_draft":6,"_partial":6,"_locale":7,"title":1174,"description":1175,"id":1176,"name":1135,"email":1136,"avatar":1137,"url":1138,"date":1177,"body":1178,"_type":1107,"_id":1186,"_source":1109,"_file":1187,"_stem":1188,"_extension":1112},"/comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1501","1501","Oh, and I just mentioned this because seeing Interlocked.Increment reminded me. Sorry for the sidetrack.",1501,"2006-06-07T02:02:37",{"type":18,"children":1179,"toc":1184},[1180],{"type":21,"tag":22,"props":1181,"children":1182},{},[1183],{"type":26,"value":1175},{"title":63,"searchDepth":130,"depth":130,"links":1185},[],"content:comments:extending_httpapplication_with_session_counts_and_uptime_in_c:1501.md","comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1501.md","comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1501",{"_path":1190,"_dir":1131,"_draft":6,"_partial":6,"_locale":7,"title":1191,"description":1192,"id":1193,"name":1135,"email":1136,"avatar":1137,"url":1138,"date":1194,"body":1195,"_type":1107,"_id":1208,"_source":1109,"_file":1209,"_stem":1210,"_extension":1112},"/comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1500","1500","Having read up a little on threading in .Net, I have to say I favour the Java approach, but more for what it doesn't let you do ;). At the higher level there's not much difference between them really, except for naming issues (instead of wait/notify/notifyAll available on all objects, you have a separate Monitor class with Wait/Pulse/PulseAll - a little odd choice of name but I'll ignore that). However, .Net clearly lets you get at the more fundamental building blocks of threading, namely at mutexes and semaphores (and the atomic inc/dec/exchange/check&exchange which are simple & ok).",1500,"2006-06-07T02:00:07",{"type":18,"children":1196,"toc":1206},[1197,1201],{"type":21,"tag":22,"props":1198,"children":1199},{},[1200],{"type":26,"value":1192},{"type":21,"tag":22,"props":1202,"children":1203},{},[1204],{"type":26,"value":1205},"I can see why that might be useful in some cases, but in my experience threading is such a can of worms it's nice to have it locked down to the 'recommended' approaches for business applications. Mutexes and particularly semaphores (with their lack of thread identity checks) are really, really easy to screw up so if I were using C#, I'd set internal standards to avoid them entirely and stick to Monitor. I guess .Net is being helpful here, but IMO giving these tools to inexperienced coders is like giving a razor to a tartrazine-addled toddler. :)",{"title":63,"searchDepth":130,"depth":130,"links":1207},[],"content:comments:extending_httpapplication_with_session_counts_and_uptime_in_c:1500.md","comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1500.md","comments/extending_httpapplication_with_session_counts_and_uptime_in_c/1500",1779264597079]