Code Behind Page Page /Global.asax.cs (C#)
Used by Page /Global.asax (C#)
1: using System;  
2: using System.Collections;  
3: using System.Web;  
4: using QuizNetOnline.Logic;  
5: using System.Web.SessionState;  
6: using System.Collections.Generic;  
7: using Microsoft.ApplicationBlocks.Data;  
8: using QuiznetOnline.Web.UI.BusinessClasses;  
9:   
10: namespace QuiznetOnline.Web.UI  
11: {  
12:     public class Global : HttpApplication  
13:     {  
14:         protected void Application_Start(object sender, EventArgs e)  
15:         {  
16:             Hashtable ht = (Hashtable)Application["SESSION_LIST"];  
17:             if (ht == null)  
18:             {  
19:                 ht = new Hashtable();  
20:                 lock (Application)  
21:                 {  
22:                     Application["SESSION_LIST"] = ht;  
23:                     Application["OnlineUsers"] = 0;  
24:                 }  
25:             }  
26:   
27:             Dictionary<string, HttpSessionState> sessionData =new Dictionary<string, HttpSessionState>();  
28:             Application["sessionData"] = sessionData;  
29:         }  
30:   
31:         protected void Application_End(object sender, EventArgs e)  
32:         {  
33:         }  
34:   
35:         protected void Session_Start(object sender, EventArgs e)  
36:         {  
37:             FormOperations.GetClientDateTimeFromCookieUpdate(Request);  
38:   
39:             // Code that runs when a new session is started  
40:             Hashtable ht = (Hashtable)Application["SESSION_LIST"];  
41:             if (ht.ContainsKey(Session.SessionID) == false)  
42:             {  
43:                 ht.Add(Session.SessionID, Session);  
44:             }  
45:   
46:             lock (Application)  
47:             {  
48:                 int i = (int)Application["OnlineUsers"];  
49:                 i++;  
50:                 Application["OnlineUsers"] = i;  
51:             }  
52:   
53:             UserWeb userWeb = new UserWeb();  
54:   
55:             userWeb.SessionStartDateTime = DateTime.Now;  
56:             if (string.IsNullOrEmpty(User.Identity.Name))  
57:             {  
58:                 userWeb.UserName = "guest@quiznetonline.com";  
59:             }  
60:             else  
61:             {  
62:                 userWeb.UserName = User.Identity.Name;  
63:                 userWeb.LoadProfileDetails(userWeb.UserName,new SqlWrapper());  
64:             }  
65:             userWeb.UserLocation = new UserLocation(Request.ServerVariables["REMOTE_HOST"] ?? string.Empty);  
66:   
67:             Session.Add("userWeb", userWeb);  
68:   
69:             //Add session to an dictionary therefore we can read the dictionary to get all the values  
70:             Dictionary<string, HttpSessionState> sessionData = (Dictionary<string, HttpSessionState>)Application["sessionData"];  
71:   
72:             if (sessionData.ContainsKey(HttpContext.Current.Session.SessionID))  
73:             {  
74:                 sessionData.Remove(HttpContext.Current.Session.SessionID);  
75:                 sessionData.Add(HttpContext.Current.Session.SessionID,  
76:                                 HttpContext.Current.Session);  
77:             }  
78:             else  
79:             {  
80:                 sessionData.Add(HttpContext.Current.Session.SessionID,  
81:                                 HttpContext.Current.Session);  
82:             }  
83:             Application["sessionData"] = sessionData;  
84:   
85:             //ENABLE TRACING ON PAGE IF SPECIFIED  
86:             if (Context.Request.QueryString["trace"] == "true")  
87:                 Context.Trace.IsEnabled = true;  
88:   
89:             Log log = new Log();  
90:             log.UserWeb = userWeb;  
91:             log.LogArea = "Session Started";  
92:             log.Save(new SqlWrapper());  
93:         }  
94:   
95:         protected void Session_End(object sender, EventArgs e)  
96:         {  
97:             // Code that runs when a session ends.    
98:             // Note: The Session_End event is raised only when the sessionstate mode  
99:             // is set to InProc in the Web.config file. If session mode is set to StateServer    
100:             // or SQLServer, the event is not raised.  
101:             Session.Clear();  
102:             Hashtable ht = (Hashtable)Application["SESSION_LIST"];  
103:             ht.Remove(Session.SessionID);  
104:   
105:             lock (Application)  
106:             {  
107:                 int i = (int)Application["OnlineUsers"];  
108:                 i--;  
109:                 Application["OnlineUsers"] = i;  
110:             }  
111:         }  
112:   
113:         //protected void Application_Error(Object sender, EventArgs e)  
114:         //{  
115:         //    //At this point we have information about the error  
116:         //    HttpContext ctx = HttpContext.Current;  
117:   
118:               
119:         //    Exception exception = ctx.Server.GetLastError();  
120:   
121:         //    try  
122:         //    {  
123:         //        Session["objErr"] = exception;  
124:   
125:         //        // --------------------------------------------------  
126:         //        // To let the page finish running we clear the error  
127:         //        // --------------------------------------------------  
128:         //        ctx.Server.ClearError();  
129:   
130:         //        Server.Transfer("~/Error.aspx");  
131:         //    }  
132:         //    catch (Exception)  
133:         //    {  
134:         //    }  
135:         //}  
136:     }  
137: }

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.