Thursday, 13 November 2014

Display Number of Online Users Asp.net- Using Global.asax file

Global .asax file-
  1. <%@ Application Language="C#" %>  
  2.   
  3. <script runat="server">  
  4.   
  5.     void Application_Start(object sender, EventArgs e)   
  6.     {  
  7.         // Code that runs on application startup  
  8.         Application["TotalOnlineUsers"] = 0;  
  9.     }  
  10.       
  11.     void Application_End(object sender, EventArgs e)   
  12.     {  
  13.         //  Code that runs on application shutdown  
  14.   
  15.     }  
  16.           
  17.     void Application_Error(object sender, EventArgs e)   
  18.     {   
  19.         // Code that runs when an unhandled error occurs  
  20.   
  21.     }  
  22.   
  23.     void Session_Start(object sender, EventArgs e)   
  24.     {  
  25.         // Code that runs when a new session is started  
  26.         Application.Lock();  
  27.         Application["TotalOnlineUsers"] = (int)Application["TotalOnlineUsers"] + 1;  
  28.         Application.UnLock();  
  29.     }  
  30.   
  31.     void Session_End(object sender, EventArgs e)   
  32.     {  
  33.         // Code that runs when a session ends.   
  34.         // Note: The Session_End event is raised only when the sessionstate mode  
  35.         // is set to InProc in the Web.config file. If session mode is set to StateServer   
  36.         // or SQLServer, the event is not raised.  
  37.         Application.Lock();  
  38.         Application["TotalOnlineUsers"] = (int)Application["TotalOnlineUsers"] - 1;  
  39.         Application.UnLock();  
  40.     }  
  41.          
  42. </script>
Web config-

  1. <system.web>  
  2. <sessionState mode="InProc" cookieless="false" timeout="20"></sessionState>  
  3. </system.web> 
Default.aspx -

  1. <form id="form1" runat="server">  
  2.     <div>  
  3.     <p>No. of Online Users:<asp:Label ID="Label1" runat="server" Text="Label" ForeColor="#CC0000"></asp:Label></p>  
  4.     </div>  
  5. </form>  
Default.aspx.cs -

  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3.         Label1.Text = Application["TotalOnlineUsers"].ToString();  
  4. }

Table Partitioning in SQL Server

  Table Partitioning in SQL Server – Step by Step Partitioning in SQL Server task is divided into four steps: Create a File Group Add Files ...