You are on page 1of 10

STATE MANAGEMENT IN

ASP.NET
• It is used to maintain the state of the user across multiple
pages.
{ OR }
Web server maintaining client information with out any
connectivity is called as state management .This can be
implemented in various ways
1.View State [ Hidden field ]
2. Page Submission
3.Cookies
4.Session
5.Query String
6.Application
7. Cache
View State
• It is the concept of persisting controls
properties between requests under post back
implementation.
• The view state will be implemented based
on hidden field.
Points to remember about view state
• The main advantage of view state will be 2 things
• There is no programming required from the developer so less
burden on the developer.
• The memory will not be allocated in the client system nor at
in the webserver system.It will be maintained as the part of
the web page itself.
• The problem with a view state is there will be more amount
of data transfer between client and web server.
• The view state can be controlled at the 3 levels 
1 } Control Level 
<Input = ….Enable viewstate=“true/false”>
Note : when it comes to sensitive data it is not
recommended to implement view state the sensitive data can
be password,credit card no, etc.
Points to remember about view state
• When you go with password type textbox the view state
will not be applicable implicitly.
• 2} Page Level
<%@ Pagedirective …..enable viewstate=“true/false” >
• 3 }Application Level 
It requires web config
It will be applicable to all the web pages
COOKIES
• It is used to maintain the server side information at the client
system. { OR } A cookie can be defined as a small amount of
memory used by the web server on the client system.
Usage : The main purpose of cookies will be storing perosonal
information of the client,it can be username,pwd,no of
visits,session id.
• Cookies can be of 2 types:-
• Client Side Cookies If the cookie information is set using
Javascript / VbScript within an HTML page then it is said to be a
client Side Cookies.
• Server Side CookiesIf the cookie information is set using server
side technology then it is said to be server side cookies.They are of
2 types:
1] Persistant Cookies ( Permanent Cookies )
2] nonPersistant Cookies ( Temporary Cookies )
• 1] Persistant Cookies ( Permanent Cookies )
– When the cookie is stored on to the hard disk
memory then it is called as persistant cookie.
– When you provide expires than the cookie will
be considered as persistent.

• 2] nonPersistant Cookies ( Temporary


Cookies )
– When the cookie is stored with in the process
memory of the browser then it is called
temporary cookies.
Syntax
• To set the cookies information
Response.cookies(“cookie name”).value =
value
• To get or read the value from a cookie
variable =
request.cookies(“cookie name”).value
Points to remember about cookies
• Cookies information will be always be stored at the client
system only.
• Cookies information are browser dependent ie the values
of the cookies set by one browser cant be read by other
browser.
• If the cookie information is set by IE then that info. Will
be maintained in the memory of the browser itself.
• If the cookie information is set by Netscape Navigator
then then information will be maintained in “Cookies.txt”
file.
Points to remember about cookies
• There is no security for cookies information.
• Browsers has a capability to disable the usage of cookies
within it.
• Note  if the browser disables the cookies in it and if any
request for a web form which contains the usage of
cookies then the request will not function properly.
• User can change cookie content (or) user can delete Text
file.
• The browser will support 20 cookies towards a single
website . If we add 21st cookie then automatically the first
cookie will be deleted.
• A cookie can represent maximum of 4kb of data.
Points to remember
• To bind the cookie information to a specific domain 
response.cookies(“cookie name”).Domain =
DomainName
• To allow the different paths of the same domain to access
the cookie information 
response.cookies(“cookie name”).path = “/path….”
– note the default expiration time for the cookies is 30 min.
• To set the expiration time for the cookie info 
response.cookies(“cookie name”).expires = dateTime
• To secure the cookie information 
response.cookies(“cookie Name”).secure = booleanValue

You might also like