ASP.NET Session Management Day 28

Lecture 28 : ASP.NET Session Management



Stateless Protocol :
  • Stateless Protocols are the type of network protocols in which Client send request to the server and server response back according to current state. 

  • It does not require the server to retain session information or a status about each communicating partner for multiple request. 

Some features of Stateless Protocols :
  • Stateless Protocol simplify the design of Server.

  • The stateless protocol requires less resources because system do not need to keep track of the multiple link communications and the session details.

  • In Stateless Protocol each information packet travel on it’s own without reference to any other packet.

  • Each communication in Stateless Protocol is discrete and unrelated to those that precedes or follow.

1) Why is http Stateless Protocol ?
  • HTTP is called as a stateless protocol because each request is executed independently, without any knowledge of the requests that were executed before it, which means once the transaction ends the connection between the browser and the server is also lost.

Stateful Protocol :
  • In Stateful Protocol If client send a request to the server then it expects some kind of response, if it does not get any response then it resend the request.  

Some features of Stateful Protocols :
  • Stateful Protocols provide better performance to the client by keeping track of the connection information.

  • Stateful Application require Backing storage.

  • Stateful request are always dependent on the server-side state.

  • TCP session follow stateful protocol because both systems maintain information about the session itself during its life.

2) How to make it Stateful in MVC core ?
  • In order to make HTTP stateful , we use session management techniques. 

  • So that, it uses the data coming from previous request while processing present request i.e, it uses the same connection for a series of client server interactions.

3) What are Cookies and What are Session Variables ?

Cookies :
  • Cookies are only stored on the client-side machine.

  • Server script sends a set of cookies to the browser. 

  • When next time browser sends any request to web server then it sends those cookies information to the server and server uses that information to identify the user.

Session :
  • A session creates a file in a temporary directory on the server where registered session variables and their values are stored. 

  • A Aession ends when the user closes the browser or after leaving the site, the server will terminate the session after a predetermined period of time.

4) How to enable Sessions in MVC core ?
  • To use session in our Application, we need to add this package as a dependency in project.json file.

  • The next step is to configure session in Startup class.

  • We need to call "AddSession" method in ConfigureServices method of startup class.

The startup class contains two methods :

Configure & ConfigureServices :
  • Declaration of this method is not mandatory in startup class. This method is used to Configure services that are used by the application. 

  • When the application is requested for the first time, it calls ConfigureServices method.

Example :
  • Inspect the cookies :

  • Delete the cookies :

Program :

Comments

Popular posts from this blog

Basic Concept In C Sharp Day 16

VS Code In JavaScript Day 6

ASP.NET MVC Interview Questions Part - II Day 26