Tag Archives: ASP.NET

ASP.NET is a server-side Web application technology designed for Web development. ASP.Net is the one of the widely used web framework to developed the web applications provided by Microsoft.

Create user control for the footer of the your web application in asp.net

With the help of the following tutorial, you can create a user control for the footer of your web application. The article demonstrates how you can create a user control and how can you use that. In this article code is written using Visual Studio 2008. So first you need to add a web user control in your project, just follow these instructions: Continue reading

How to use Session Events: Session_OnStart and Session_OnEnd

There are two important session events related to session state in asp.net, one is Session_OnStart and another is Sesson_OnEnd. You can use both events in the Global.asax file in your asp.net application or websites. The Session_Start event is raised when first time session starts and Sesosion_End event raises whenever session end. Global.ascx file must be located in the root directory of the application. So you just need to create two subroutine in the Global.ascx file as:

  1. Public Sub Session_OnStart()
  3. End Sub
  5. Public Sub Session_OnEnd()
  7. End Sub

We can understand these event by taking a simple example to show the Number of the active users of the website. In this example we will create a counter by adding 1 in the application state variable ‘NoOfOnlineUsers’ on the session start and subtracting 1 from this variable on the session end

  1. public void Application_OnStart()
  2. {
  3.   Application["NoOfOnlineUsers"] = 0;
  4. }
  6. public void Session_OnStart()
  7. {
  8.   Application["NoOfOnlineUsers"] = (int)Application["NoOfOnlineUsers"] + 1;
  9. }
  11. public void Session_OnEnd()
  12. {
  13.   Application["NoOfOnlineUsers"] = (int)Application["NoOfOnlineUsers"] - 1;
  14. }

From the above example you can understand the basics of the both events if you want to do more then you could do so by using these events. You can also use these events to track some more session-related information.

One more things as MSDN says ‘If the Global.asax file or Web.config file for an ASP.NET application is modified, the application will be restarted.‘ this means your Application["NoOfOnlineUsers"] value will be zero if you modified these files.

If some person does not do any action on the a page or page remains idle for some specified time then web server assumes that user left the page and then Session_OneEnd event will be raised.