3. Q. WHAT IS STATE MANAGEMENT ?
State Management is very important feature in Asp.net .
State Management is a process by which state and page
information is maintained over multiple requests for same or
different pages.
State management maintains and stores the information of any
user till the end of the user session .
As HTTP is a stateless protocol ,server does not store any
information once the response is sent back to client based on his
request.
Web server does not have any idea about the requests.
When user submits request again, the server treats it as a new
user.
E.g. Online registration form.
4. So, to retain the values of the controls
we use state management techniques.
They are classified into the following
two categories :-
❖ Client side state management -
• Which Utilizes Client Resources
• Ways:View state , Control State,
Hidden Field State, Cookies,
Query Strings, Cache.
❖ Server side state management -
• Which Utilizes Server Resources
• Ways: Session State, Application
State
7. Features of view state –
o Retains the value of the control after post-back without using a session.
o Stores the value of pages and control properties defined in the page.
o Creates a custom View State Provider that lets us store view state information in a
SQL server database or in another data store.
Advantages -
o Easy to Implement.
o No server resources are required.The View State is contained in a structure within the page
load.
o Enhanced security features: It can be encoded and compressed or Unicode implementation.
Disadvantages -
o Security risk
o Performance Consideration
o Device limitation
10. Q. WHAT IS QUERY STRING ?
o A Query String contains the information that is sent to server with URL.
o The URL part which comes after the ? Symbol is called QueryString.
o It has two parts , a key and a value. Like for E.G.- ?query=foo , here query is the
key and foo Is its value.
11. Advantages -
o It is very lightweight and will not consume any server resources.
o It is very easy to use and it is the most efficient state management
technique.
o Simple implementation.
Disadvantages -
o We can pass information only as a string.
o URL length has limitations. So we can’t send much information
through URL.
o Information passed is clearly visible to everyone and can be easily
altered/Potential Security Risk.
o Limited capacity
16. COOKIES
OR
Q. ROLE OF COOKIES IN ASP.NET
ASP.NET Cookie is a small bit of text that is used to store
user-specific information.
This information can be read by the web application whenever
user visits the site.
When a user requests for a web page, web server sends not just a
page, but also a cookie containing the date and time.
18. ❑ Persist Cookie
When cookies are saved within the browser’s temporary folder on the
client’s machine, such cookies are said to be persisted, because
information saved can be retrieved at any time, so long the cookies’
expiration date has not elapsed.
❑ Non-Persist
Cookies
Also known as session or in-memory cookies, these are only useable while
the browser is open.They are not saved locally on the client’s machine.
19. Advantages of Cookies -
o Its clear text so user can able to read it
o We can store user preference information on the client machine.
o Its easy way to maintain.
o Fast accessing.
Disadvantages of Cookies -
o If user clears cookie information we can't get it back.
o No security
o Each request will have cookie information with page.
20. protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie Username = new
HttpCookie("UserName","WELCOME");
Username.Expires=DateTime.Now.AddYears(1);
Response.Cookies.Add(Username);
}
Q.Write a program to create a new cookie with the name
“Username” and add it to the HTTP Response object on the click of
a button. Set the expiry date of the cookie to One year from Now.
❖ Code
24. ❖ APPLICATION STATE
o It is used to store global application specific information.
o Automatically created when a first request is made to a web application.
o Storing Application state in the server’s memory is better than storing the
information in the database.
o It is server side state management mechanism.
o The application state is used same as session, but the difference is, the
session state is specific for a single user; where as an application state is
common for all users.
25. Advantages
o Application scope
o Simple implementation
Disadvantages
o Requires server resources
o Limited durability of data (server cash or shutdown)
26. EXAMPLE -
HERE WE ARE GOING TO CALCULATE HOW MANY TIMES A
GIVEN PAGE HAS BEEN VISITED BY VARIOUS CLIENTS.