Search Your Dot Net Topic

Friday 30 April 2021

asp.net session management example | using session in asp.net C# | what ...





WHAT IS SESSION?

Session provides a facility to store information on server memory not in browser. 

Session created in server memory.

It can store any type of object. (System.Object)






WHY WE NEED SESSION?

HTTP is stateless protocol, its forgot everything after response. 

To keep some data in process we required SESSION.

Session keep our valuable and important data on server,
On any page we can call the same.





ADVANTAGES:
Help to maintain user data all over the application.
Easy to implement.
Store any kind of Object.
Store / Keep each User data store separately.
Its Very Much Secure.




DISADVANTAGES:
Default session timeout is 20 minutes.
Loss of Data when session expired.
More session more burden on server.
Overhead involved in serializing and De-Serializing session data





HOW TO CREATE A SESSION?
SYNTAX:
Session[“NAME OF SESSION”] =  <OBJECT>
EXAMPLE:
Session[“LoginUser”] = txtUserName.Text;
(This will create a SESSION called LOGINUSER.)







HOW TO USE A SESSION?
EXAMPLE:
string UserName = Convert.ToString(Session[“LoginUser”]);
(This will convert session object LOGINUSER into string.)






No comments:

Post a Comment