SlideShare a Scribd company logo
SESSIONS & COOKIES
Are state management techniques (used to maintain the state of the application
since http is a stateless protocol).
Basic about State Management in ASP.NET
• ASP.NET framework provides various ways to preserve
states at various stage.
• Controlstate, viewstate, sessions, cookies etc.
• This can be categorised as client side and server side
state management techniques.
SESSIONS
• Session stores variables on the Server Side.
• Session will allocates memory in the web server and for every
user server will allocates memory, so Session is per user
based.
• Sessions are generally used to maintain state when you
navigate through a website. However, they can also be used to
hold commonly accessed objects.
• Every session is identified by a unique session id.
• Sessions are not reliant on the user allowing a cookie. They
work instead like a token allowing access and passing
information while the user has their browser open.
• The problem with sessions is that when you close your
browser you also lose the session. So, if you had a site
requiring a login, this couldn't be saved as a session like it
could as a cookie, and the user would be forced to re-login
every time they visit.
EXAMPLE:
Session["Name"] = “textName”;
Response.Write(Session[“Name"]);
Code Explanation:-
• The first line of code takes the value of the Name textbox
control and stores it in the Session object. By specifying the
code of Session["Name"] , we are giving the property a name
called "Name." By specifying a name for the property, it
becomes easier to retrieve it at a later point in time.
• The next line of code retrieves the stored value from the
Session object. It then writes this value via the
'Response.Write' method back to the client.
ADVANTAGES AND DISADVANTAGES
• Advantages:
 Session provide us a way to maintain user data, all over
the applications.
 We can store any type of object in it.
 Session is secure and transparent from the user.
• Disadvantages:
 Performance overhead in case of large volumes of user,
because data is stored in server memory.
COOKIES
• Basically a cookie is Client Side variable and will store data either in browser or in
system hard disk.
• Cookies are stored per-user on the users machine. A cookie is usually just a bit of
information.
• You can never fully trust that a cookie has not been tampered with by a user or
outside source however if security is a big concern and you must use cookies then
you can either encrypt your cookies or set them to only be transmitted.
• A user can clear there cookies at any time or not allow cookies altogether so you
cannot count on them being there just because a user has visited your site in the
past.
• A cookie can keep information in the user's browser until deleted. If a person has a
login and password, this can be set as a cookie in their browser so they do not have
to re-login to your website every time they visit.
• You can store almost anything in a browser cookie.
• The trouble is that a user can block cookies or delete them at any time. If, for
example, your website's shopping cart utilized cookies, and a person had their
browser set to block them, then they could not shop at your website.
EXAMPLE:
<%
Response.Cookies("firstname")=“mlsu”;
Response.Cookies("firstname").Expires=#May 10,2019#;
%>
Code Explanation:-
• Here we will create a cookie named "firstname" and assign the value
“mlsu" to it. And in the second line we are setting a date, when the
cookie should expire.
<%
fname=Request.Cookies("firstname");
Response.Write("Firstname=" & fname);
%>
Code Explanation:-
• We retrieve the value of the cookie named "firstname" and display it
on a page.
ADVANTAGES AND DISADVANTAGES
• Advantages:
 It is very simple to use and implement.
 Browser is in-charge of sending data.
 For multiple sites with cookies, the browser automatically
arranges them.
• Disadvantages:
 It stores data in simple text format, so it’s not secure at all.
There is a size limit for cookies data(4KB).
Most browsers provide limits for number of cookies at a time
which is 20.
DIFFERENCE BETWEEN COOKIES AND
SESSION
Note: You can of course get the best of both worlds! Once you know
what each does, you can use a combination of cookies and sessions to
make your site work exactly the way you want it to.
1. Client-side state management
technique, stored in on client's
browser.
2. Can store text data.
3. Not suggestible for storing
critical information.
4. Cookie doesn't have a self-
expiry time.
1. Server-side state management
technique, stored in server.
2. Can stored an object.
3. Can be used for storing critical
information.
4. Session expires after 20
minutes by default.
Cookies Sessions
THANK YOU

More Related Content

PPTX
Cookies in servlets.ppt
Swetha S
 
PPTX
Protect Your System - Use Browser Junk Removal Tool
stocksben
 
PPTX
APEX & Cookie Monster
Christian Rokitta
 
PPTX
Using cookies and sessions
Nuha Noor
 
ODP
Caching idea for midcom
tepheikk
 
PPTX
Cookies authentication
Rsilwal123
 
PPTX
State Management.pptx
DrMonikaPatel2
 
Cookies in servlets.ppt
Swetha S
 
Protect Your System - Use Browser Junk Removal Tool
stocksben
 
APEX & Cookie Monster
Christian Rokitta
 
Using cookies and sessions
Nuha Noor
 
Caching idea for midcom
tepheikk
 
Cookies authentication
Rsilwal123
 
State Management.pptx
DrMonikaPatel2
 

Similar to Sessions&cookies (20)

PPTX
Enterprise java unit-2_chapter-2
sandeep54552
 
PPTX
Enterprise java unit-2_chapter-3
sandeep54552
 
PPTX
Authentication in Svelte using cookies.pptx
Knoldus Inc.
 
PDF
Session and Cookies.pdf
HamnaGhani1
 
PPT
Cookies in servlet
chauhankapil
 
PPTX
Session and cookies,get and post
baabtra.com - No. 1 supplier of quality freshers
 
PDF
E Commerce Analytics Demandware
loripelletier
 
PPT
session and cookies.ppt
Jayaprasanna4
 
PPTX
Cookies and Session
KoraStats
 
PDF
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
kalichargn70th171
 
PPTX
Cookies testing
abhi2632
 
PPTX
Backend Technologies Notes ajef;asnfkndfdsa
itsmepulkitsharma
 
PPTX
Cookies: HTTP state management mechanism
Jivan Nepali
 
PPTX
Session & Cookies
university of education,Lahore
 
PPTX
Session & Cookies
university of education,Lahore
 
PPTX
C# cookieless session id and application state
Malav Patel
 
PPTX
Cookie & Session In ASP.NET
ShingalaKrupa
 
PPTX
State management in ASP .NET
baabtra.com - No. 1 supplier of quality freshers
 
PPSX
Sessions and cookies
www.netgains.org
 
PPT
PHP - Introduction to PHP Cookies and Sessions
Vibrant Technologies & Computers
 
Enterprise java unit-2_chapter-2
sandeep54552
 
Enterprise java unit-2_chapter-3
sandeep54552
 
Authentication in Svelte using cookies.pptx
Knoldus Inc.
 
Session and Cookies.pdf
HamnaGhani1
 
Cookies in servlet
chauhankapil
 
Session and cookies,get and post
baabtra.com - No. 1 supplier of quality freshers
 
E Commerce Analytics Demandware
loripelletier
 
session and cookies.ppt
Jayaprasanna4
 
Cookies and Session
KoraStats
 
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
kalichargn70th171
 
Cookies testing
abhi2632
 
Backend Technologies Notes ajef;asnfkndfdsa
itsmepulkitsharma
 
Cookies: HTTP state management mechanism
Jivan Nepali
 
C# cookieless session id and application state
Malav Patel
 
Cookie & Session In ASP.NET
ShingalaKrupa
 
Sessions and cookies
www.netgains.org
 
PHP - Introduction to PHP Cookies and Sessions
Vibrant Technologies & Computers
 
Ad

Recently uploaded (20)

PDF
UI/UX Developer Guide: Tools, Trends, and Tips for 2025
Penguin peak
 
PPTX
B2B_Ecommerce_Internship_Simranpreet.pptx
LipakshiJindal
 
PPTX
LESSON-2-Roles-of-ICT-in-Teaching-for-learning_123922 (1).pptx
renavieramopiquero
 
PPTX
Parallel & Concurrent ...
yashpavasiya892
 
PPT
Introduction to dns domain name syst.ppt
MUHAMMADKAVISHSHABAN
 
PPTX
Black Yellow Modern Minimalist Elegant Presentation.pptx
nothisispatrickduhh
 
PDF
The Internet of Things (IoT) refers to a vast network of interconnected devic...
chethana8182
 
PPTX
Google SGE SEO: 5 Critical Changes That Could Wreck Your Rankings in 2025
Reversed Out Creative
 
PPTX
Pengenalan perangkat Jaringan komputer pada teknik jaringan komputer dan tele...
Prayudha3
 
PPTX
The Latest Scam Shocking the USA in 2025.pptx
onlinescamreport4
 
PPTX
How tech helps people in the modern era.
upadhyayaryan154
 
PPTX
Microsoft PowerPoint Student PPT slides.pptx
Garleys Putin
 
PDF
Data Protection & Resilience in Focus.pdf
AmyPoblete3
 
PDF
PDF document: World Game (s) Great Redesign.pdf
Steven McGee
 
PPT
Transformaciones de las funciones elementales.ppt
rirosel211
 
PPTX
Different Generation Of Computers .pptx
divcoder9507
 
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
APNIC
 
PPTX
Unlocking Hope : How Crypto Recovery Services Can Reclaim Your Lost Funds
lionsgate network
 
PPTX
AI ad its imp i military life read it ag
ShwetaBharti31
 
PDF
LB# 820-1889_051-7370_C000.schematic.pdf
matheusalbuquerqueco3
 
UI/UX Developer Guide: Tools, Trends, and Tips for 2025
Penguin peak
 
B2B_Ecommerce_Internship_Simranpreet.pptx
LipakshiJindal
 
LESSON-2-Roles-of-ICT-in-Teaching-for-learning_123922 (1).pptx
renavieramopiquero
 
Parallel & Concurrent ...
yashpavasiya892
 
Introduction to dns domain name syst.ppt
MUHAMMADKAVISHSHABAN
 
Black Yellow Modern Minimalist Elegant Presentation.pptx
nothisispatrickduhh
 
The Internet of Things (IoT) refers to a vast network of interconnected devic...
chethana8182
 
Google SGE SEO: 5 Critical Changes That Could Wreck Your Rankings in 2025
Reversed Out Creative
 
Pengenalan perangkat Jaringan komputer pada teknik jaringan komputer dan tele...
Prayudha3
 
The Latest Scam Shocking the USA in 2025.pptx
onlinescamreport4
 
How tech helps people in the modern era.
upadhyayaryan154
 
Microsoft PowerPoint Student PPT slides.pptx
Garleys Putin
 
Data Protection & Resilience in Focus.pdf
AmyPoblete3
 
PDF document: World Game (s) Great Redesign.pdf
Steven McGee
 
Transformaciones de las funciones elementales.ppt
rirosel211
 
Different Generation Of Computers .pptx
divcoder9507
 
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
APNIC
 
Unlocking Hope : How Crypto Recovery Services Can Reclaim Your Lost Funds
lionsgate network
 
AI ad its imp i military life read it ag
ShwetaBharti31
 
LB# 820-1889_051-7370_C000.schematic.pdf
matheusalbuquerqueco3
 
Ad

Sessions&cookies

  • 1. SESSIONS & COOKIES Are state management techniques (used to maintain the state of the application since http is a stateless protocol).
  • 2. Basic about State Management in ASP.NET • ASP.NET framework provides various ways to preserve states at various stage. • Controlstate, viewstate, sessions, cookies etc. • This can be categorised as client side and server side state management techniques.
  • 3. SESSIONS • Session stores variables on the Server Side. • Session will allocates memory in the web server and for every user server will allocates memory, so Session is per user based. • Sessions are generally used to maintain state when you navigate through a website. However, they can also be used to hold commonly accessed objects. • Every session is identified by a unique session id. • Sessions are not reliant on the user allowing a cookie. They work instead like a token allowing access and passing information while the user has their browser open. • The problem with sessions is that when you close your browser you also lose the session. So, if you had a site requiring a login, this couldn't be saved as a session like it could as a cookie, and the user would be forced to re-login every time they visit.
  • 4. EXAMPLE: Session["Name"] = “textName”; Response.Write(Session[“Name"]); Code Explanation:- • The first line of code takes the value of the Name textbox control and stores it in the Session object. By specifying the code of Session["Name"] , we are giving the property a name called "Name." By specifying a name for the property, it becomes easier to retrieve it at a later point in time. • The next line of code retrieves the stored value from the Session object. It then writes this value via the 'Response.Write' method back to the client.
  • 5. ADVANTAGES AND DISADVANTAGES • Advantages:  Session provide us a way to maintain user data, all over the applications.  We can store any type of object in it.  Session is secure and transparent from the user. • Disadvantages:  Performance overhead in case of large volumes of user, because data is stored in server memory.
  • 6. COOKIES • Basically a cookie is Client Side variable and will store data either in browser or in system hard disk. • Cookies are stored per-user on the users machine. A cookie is usually just a bit of information. • You can never fully trust that a cookie has not been tampered with by a user or outside source however if security is a big concern and you must use cookies then you can either encrypt your cookies or set them to only be transmitted. • A user can clear there cookies at any time or not allow cookies altogether so you cannot count on them being there just because a user has visited your site in the past. • A cookie can keep information in the user's browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. • You can store almost anything in a browser cookie. • The trouble is that a user can block cookies or delete them at any time. If, for example, your website's shopping cart utilized cookies, and a person had their browser set to block them, then they could not shop at your website.
  • 7. EXAMPLE: <% Response.Cookies("firstname")=“mlsu”; Response.Cookies("firstname").Expires=#May 10,2019#; %> Code Explanation:- • Here we will create a cookie named "firstname" and assign the value “mlsu" to it. And in the second line we are setting a date, when the cookie should expire. <% fname=Request.Cookies("firstname"); Response.Write("Firstname=" & fname); %> Code Explanation:- • We retrieve the value of the cookie named "firstname" and display it on a page.
  • 8. ADVANTAGES AND DISADVANTAGES • Advantages:  It is very simple to use and implement.  Browser is in-charge of sending data.  For multiple sites with cookies, the browser automatically arranges them. • Disadvantages:  It stores data in simple text format, so it’s not secure at all. There is a size limit for cookies data(4KB). Most browsers provide limits for number of cookies at a time which is 20.
  • 9. DIFFERENCE BETWEEN COOKIES AND SESSION Note: You can of course get the best of both worlds! Once you know what each does, you can use a combination of cookies and sessions to make your site work exactly the way you want it to. 1. Client-side state management technique, stored in on client's browser. 2. Can store text data. 3. Not suggestible for storing critical information. 4. Cookie doesn't have a self- expiry time. 1. Server-side state management technique, stored in server. 2. Can stored an object. 3. Can be used for storing critical information. 4. Session expires after 20 minutes by default. Cookies Sessions

Editor's Notes

  • #10: the main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not. This difference determines what each is best used for.