Unit 5
Unit 5
State Management
•
State management meaeb page, object/data, and user in the application explicitly
because all ASP.NET web applications are stateless, i.e., by default, for each page
posted to the server, the state of controls is lost. Nowadays all web apps demand a
high level of state management from control to application level.
•
HTTP/HTTPs doesn't remember what website or URL we visited, or in other
words we can say it doesn't hold the state of a previous website that we visited
before closing our browser, that is called stateless.
State Management
•
ASP.NET Core MVC provides a rich set of features for building modern web
applications, and these include support for a number of ways to manage state.
•
State management is the technique of maintaining the state of an application over
time, i.e., for the duration of a user session or across all of the HTTP requests and
responses that constitute the session.
•
Thus it is one of the most important cross-cutting concerns of any web
application.
State Management
State management
•
Types of state management
1. There are two types of state management techniques: client side
and server side.
Client side Server side
Cookies Application
HiddenField Session
•
This architecture is something like the following,
•
Server-Side State Management
•
Server-Side State Management is different from Client-Side State Management but the operations
and working is somewhat the same in functionality. In Server-Side State Management all the
information is stored in the user memory. Due to this functionality there is more secure domains at
the server side in comparison to Client-Side State Management.
•
The structure is something like the following,
•
Cookies
•
A set of Cookies is a small text file that is stored in the user's hard drive using the client's browser.
Cookies are just used for the sake of the user's identity matching as it only stores information such
as sessions id's, some frequent navigation or post-back request objects.
•
Whenever we get connected to the internet for accessing a specific service, the cookie file is
accessed from our hard drive via our browser for identifying the user. The cookie access depends
upon the life cycle or expiration of that specific cookie file.
•
Cookie | Types
1. Persistent Cookie
2. Non-Persistent Cookie
Persistent Cookie
•
Cookies having an expiration date is called a persistent cookie. This type of cookie reaches their
end as their expiration dates comes to an end. In this cookie we set an expiration date.
options.Expires = DateTime.Now.AddSeconds(10);
Non-Persistent Cookie
•
Non-Persistent cookies are temporary. They are also called in-memory
cookies and session-based cookies.
•
These cookies are active as long as the browser remains active, in other
words if the browser is closed then the cookies automatically expire
•
It maintains user information as long as the user access or uses the services. Its
simply the opposite procedure of a persistent cookie.
cookies
•
Some features of cookies are:
4. User Preferred
http://localhost:5655/api/customer?region=abc
And, the code snippet below shows how you can read the query string data in your action
method.
• Session state is a mechanism for storing user data on the server side in an
ASP.NET Core MVC web application.
• A user’s browser sends the server a request containing information about the
user’s session every time the user visits a website.
• The server then creates a new session and stores the user’s data in that session.
HttpContext.Session.SetString("name", name);
RedirectToAction("list", "Student");
Session
The session is stored in the following for ways in ASP.NET.
InProcMode
It is a default session mode and a value store in web server memory (IIS).
In this the session value stored with server start and it ends when the
server is restarted.
State Server Mode
In this mode session data is stored in separate server.
Session
SQL Server Mode
In this session is stored in the database. It is a secure mode.
Custom Mode
Generally under session data is stored in InProc, Sql Server, State server,
etc. If you store session data with other new techniques then provide
ASP.NET.
Application
Application State is a server side management state. It is also called
application level state management. In this mainly store user activity in
server memory and application event shown in Global.asax file.
Their are three stages of applications in ASP.NET.
Application_Start
This event begins with domain start.
Void Application_Start(object sender, EventArgs e)
{
Application["AppstartMessage"] = "Welcome to Developer Communtiy";
}
Application
Application_Error
void Application_Error(object sender,
EventArgs e)
{
// Write an unhandled error code exception
}
Application
Application_ End
• [TestClass]
• {
• [TestMethod]
• {
• int moduleId = 2;
• // 2 - Act
• // 3 - Assert