ASP .NET Session Management

 

Q. Why http protocol is called as stateless ?

  • HTTP protocol is called as stateless because the http server not keeps the record of any information.
  • When client requests to server, every time request treated independently(it not checks whether it requested before or not) by server.
  • We can also say that when client ends the process of any task the connection between server and browser also terminated.
  • In below example we can see that after accessing browser when we again access the value of i starts again from 0. 
                                                

Stateless Protocol :

  • Stateless protocols are the protocols in which client sends request to server and server response back to client based on current state. 
  • Server not require to maintain information of each client with multiple requests.
Some important features of stateless protocol are :
  • They simplify the server design.
  • They require less resources because system not keep records and session details.
  • They not require any reference for any packet.

Q. How to make http protocol stateful?

  • To make http protocol stateful, we can use session management techniques.
  • It uses data coming from previous request in present request.
  • It uses same connection for series of client server interaction for limited time.
  • In below example we can see that we used sessions here and the value gets incrementing whenever we access before terminating the task.


Q. What are cookies?

  • Cookies are the state/session management techniques, which we can use for storing information for later use.
  • Cookies are the small text files that are created in browser memory for temporary or on hard-disk for permanent.

Q. What are sessions?

  • We can say that session means a time period for something.
  • In session variables we can store user's information and destroy session when user log out.
  • It stores values as an object like a dictionary, so typecasting is necessary while retrieving the value.
  • To avoid the null exception we must do null check before retrieving the value.
  • Session passes data from controller to view.
  • We also have some session behavior attributes like default, required, readonly, disabled.

Example :

1) When we inspect the cookies :


2) When we delete cookies the task gets terminated and session variables set to default value again. And also we see the size gets changed :




Thank You!!!

For more understanding watch below video :
 

Comments

Popular posts from this blog

Day 3 : JavaScript

SQL Concepts-1