Thursday, May 6, 2021

ASP.NET Session Management

 ASP.NET Session Management


1.Why is http protocol stateless ?
  • Http is called as a stateless protocol because each request sends without any knowledge of that request. 
  • means once the request sends to the server after responding to that request, the server lost that connection.

In our application, I go to the HomeController and in that First, I sends the request to the index. So let's see:



Here I create a variable that is i=0 and increment that as an i++. And I also put the debug point when I run this first GET request is sent. now we see:


Now the i value is incremented here i=1. After that server responds and then end-user see the application. Now If the end-user again sends the request from the same browser. This is the second request. Now see what will happen:


See here the i becomes 0 again. This is the HTTP stateless protocol.



2.What is session variable?
  • Session is used to store or save the user data. 
  • Session stores the data on the server.




3.How to enable session in MVC core?

First we need to add the session service in the Startup.cs file and after that have to use that session as shown below.




After that we need to write the code in the controller file. For now we have only one controller(i.e. HomeController.cs).


But remember if you do not add session service in Startup.cs file then you won’t be able to run the project properly.


4.What is cookies?
  • The session uses cookies. 
  • Cookies is some piece of data which is stored in the browser.
  •  We can store users related information in cookies.

inspect the cookies :





5.How to make http stateful protocol?
  • 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.












For more understanding watch below video:






Thank you!!!!!!

No comments:

Post a Comment

Function in SQL -part 8

  In this blog we are going to understand  Sql function.   FUNCTION: A function is a database object in SQL Server. It accepts only input pa...