Skip Navigation LinksHome > Categories > Code from a Category

Chat Application Using Application State Object



User Name: codelecturer
Name: Mike Chauhan
Contact Me: www.datawebcoder.com/ContactUs.aspx
Home Page: www.datawebcoder.com
6 years of total IT experience including programming, application development, System Maintenance . 3 years of Experienced and expertise in .Net Framework VB, Visual Basic.Net, ASP.Net 2.0, 3.5 and AD... [More]
Viewed Times: 128
Add Date: 01/07/2012
In this article, I will explain small chatting example by using Application Object, I will also discuss the various events in Global.asax file.

Application State:

Application State is one of the Server Side State management Mechanism which stores application memory on the server rather than persisting data in the client side memory.If we declare any application variable in a single project, it will be accessible along the website. It will optimize the performance of the website rather than storing the data in database.Application variables save the memory by creating instance to HttpApplicationState class. We can use that variable in all pages throughout the project.Memory of Application Variable expires until we close the Web Project from the web server.

e.g.


Global Application Class [Global.asax]

Application state only achieved by adding Global.asax file into our project, it not mandatory to define Global.asax file web project, if you have not added Global.asax file, ASP.NET Runtime detects that there was no Application Statemangement in the current project.

Events in Global.asax File

Some of the Events in Global.asax file are depicted as follows; this is not a complete list of events.

Application_Start: This event fires executes when the application starts running
Application_End: This event ocurs on application shutdown
Application_Error: This event ocurs when unhandled error occurs
Session_Start: This event ocurs when new session is started.
Session_End: This event occurs when session ends

Hands on Chat Application:

This is very small application, just like kids play so there is no need to prolong my explanation on this case study by explaining each and every control and all.

Step-1:

Design web form as follows by using three textboxes and one image button. The size of the window was managed by using java script window.open () method. I created two pages one is Defalut.aspx and another one is chat.aspx. On form load event of Default.aspx, I opened chat.aspx as a popup window.



Defalut.aspx (Source Code)


Chat.aspx (Page Design)

Step-2

Add Global.asax file in you web application and manage add the code as follows


Step: 3



Step-4



Run the application in Browser and deploy it on your local IIS or access the URI in two browser and Check it will maintain the State each use session and finally my content was as follows

Here I completed only global chat without taking any session expiration and all. This is not a Full round trip for Private chat even; this is just for understanding the Application State of a web application.

Conclusion I hope this article will give brief idea on how to use Application Server State by Using Application Object. Application state variable expires after Stopping Web Server. So in order to maintain the State Permanently we will go for Customized Caching to persist the state of the Server.

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Details**:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
 
    
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.