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.

How to disable Session state on your asp.net page

Every asp.net page has the session state by default, this may decrease the total performance a little bit. So You can disable the session state from the pages when you don’t need to use sessions. And you can do so to set the false value of the EnableSessionState attribute in the page directive of your page like as: Continue reading How to disable Session state on your asp.net page

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:

Public Sub Session_OnStart()
End Sub
Public Sub Session_OnEnd()
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

public void Application_OnStart()
  Application["NoOfOnlineUsers"] = 0;
public void Session_OnStart()
  Application["NoOfOnlineUsers"] = (int)Application["NoOfOnlineUsers"] + 1;
public void Session_OnEnd()
  Application["NoOfOnlineUsers"] = (int)Application["NoOfOnlineUsers"] - 1;

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.

Late binding by Reflection in asp.net

Reflection provides objects (of type Type) that encapsulate assemblies, modules and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties. If you are using attributes in your code, Reflection enables you to access them.
Continue reading Late binding by Reflection in asp.net