SlideShare une entreprise Scribd logo
1  sur  20
PRESENTATION
ON
COOKIE AND SESSION
MANAGEMENT IN ASP .NET
Submitted To: Rachana Kamaliya
Prepared By: Kumbhani Minaxi
Limbasiya Jignasha
INDEX
 Introduction
 Overview of Session
 Session – Property/Method
 Session - Example
 Session Configuration
 Advantages And Disadvantages Of Session
 Overview Of Cookie
 How cookies Started?
 Cookie - Property
 Cookie – Example
 Advantages And Disadvantages Of Cookie
 Differences Between Session & Cookie
 References
jignasha & Minaxi
1
Session & Cookie
BASIC ABOUT STATE MANAGEMENT
 ASP.NET framework provides various ways to preserve
the states at various stage.
 controlstate, viewstate, cookies, session, etc.
 These can be defined at the client side and server side
state management
jignasha & Minaxi
3
Session & Cookie
STATE MANAGEMENT
jignasha & Minaxi
4
Session & Cookie
OVERVIEW OF SESSION
 Session is server side object.
 It is saving your data for the
session you are using the site.
 There is a time for which this
objects stay in the memory.
 Session is defined in
Web.Config for session state
section otherwise 20 mins by
default.
jignasha & Minaxi
5
Fig : For every client session
data store separately
Session & Cookie
SESSION
 The Session is active:
 Till the user closes the browser or
 A certain period expires (20 minutes )
 Every session is identified by a unique SessionID
 Created at first entry in the site
 Transmitted in a cookie by default
jignasha & Minaxi
6
Session & Cookie
PROPERTY
jignasha & Minaxi
7
Property Description
Count Gives the number of session variables which
are in memory.
Session ID Give you unique SessionID,which is assign to
your session.
TimeOut Get or Set TimeOut period.
IsNewSession A Boolean value specifies whether session is
new or old one.
IsCookieLess A Boolean value specifies whether session is
Cookless or not.
Keys A collection of all keys
Session & Cookie
METHOD
jignasha & Minaxi 8
Method Description
Session.Remove
(StrSessionName)
Remove an Item from session state
collection.
Session.RemoveAll() Remove all Items from session collection.
Session.Clear() There is no difference between clear and
RemoveAll().RemoveAll() calls
Clear().internally.
Session & Cookie
SESSION - EXAMPLE
 Session Declaration:
 Session Retriving:
 Session Removing:
 To handle events fired when a session is started or
ended we use Session_OnStart and Session_OnEnd in
the Global.asax file
jignasha & Minaxi
9
Session["username"] = "pesho";
string = Session["username"].ToString();
Session.Remove(“username");
or
Session[“username"] = null;
Session & Cookie
SESSION CONFIGURATION
 We can configure various aspects of the session
mechanism
 Use the sessionState section in Web.config
 Example:
jignasha & Minaxi
10
<system.web>
<sessionState
cookieless="true" mode="InProc"
timeout="60" cookieName="MySite" />
</system.web>
 To deny/restrict access to the session
<%@ Page EnableSessionState="False"%>
<%@ Page EnableSessionState="ReadOnly" %>
Session & Cookie
ADVANTAGES & DISADVANTAGES
Advantages:
 Session provide us the way of maintain user data
to all over the application.
 session is that we can store any kind of object in it.
:eg, database, dataset.. Etc
 Session is secure and transparent from the user.
Disadvantages:
 Performance overhead in case of large volumes of
user, because session data is stored in server memory.
jignasha & Minaxi
11
Session & Cookie
OVERVIEW OF COOKIES
 Cookies are the small files that are created on the
client's system or client browser memory.
 We can store small pieces of information in a client
system and use it when needed.
 It works transparently with the user.
 It can be easily used anywhere in your web application
jignasha & Minaxi
12
Session & Cookie
HOW COOKIE STARTED?
jignasha & Minaxi
13
Session & Cookie
HOW COOKIE STARTED?(CONT..)
jignasha & Minaxi
14
Session & Cookie
PROPERTY
Property Description
Name Specify name of cookie
Value Contains value of cookie
Expires Get or Set expiration Date of cookie.
Expired Informs you whether cookie is expired or not.
Domain Specific domain can be specified,if cookie
store in specific folder.
Path Allows you to set or get path of cookie to be
store.
jignasha & Minaxi 15
Session & Cookie
COOKIE - EXAMPLE
 working with cookies, we need to use the namespace
System.web.
 Creating a cookie that will be sent to the client Web
browser:
 Reading a cookie received at the server:
jignasha & Minaxi
16
HttpCookie cookie = new HttpCookie
("UserName", "bajivan");
Response.Cookies.Add(cookie);
HttpCookie cookie = Request.Cookies["UserName"];
Session & Cookie
ADVANTAGES & DISADVANTAGES
Advantages:
 It's very simple to use and implement.
 Browser takes care of sending the 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 the number of cookies is
20.
jignasha & Minaxi
17
Session & Cookie
1. Cookies can store only
"string" data type
2. They are stored at Client
side
3. Cookie is non-secure since
stored in text format at client
side
4. Only in few situations we
can use cookies because
of no security
1.Session can store any data
type
2. These are stored at Server
side
3. Session are secure because
it is stored in binary format
4. For all condition /situations
we can use sessions
jignasha & Minaxi
18
DIFF BETWEEN COOKIES & SESSION
Session & Cookie
REFERENCES
 http://www.codeproject.com
 http://en.wikipedia.org
 http://www.Tutorials.com
jignasha & Minaxi 19
Session & Cookie
20

Contenu connexe

Tendances

JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slidesSmithss25
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessionsSukrit Gupta
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
 
javascript objects
javascript objectsjavascript objects
javascript objectsVijay Kalyan
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.netDeep Patel
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.Ni
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NETRajkumarsoy
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technologyTanmoy Barman
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycleDhruvin Nakrani
 
Threads And Synchronization in C#
Threads And Synchronization in C#Threads And Synchronization in C#
Threads And Synchronization in C#Rizwan Ali
 
Enterprise java unit-3_chapter-1-jsp
Enterprise  java unit-3_chapter-1-jspEnterprise  java unit-3_chapter-1-jsp
Enterprise java unit-3_chapter-1-jspsandeep54552
 
RichControl in Asp.net
RichControl in Asp.netRichControl in Asp.net
RichControl in Asp.netBhumivaghasiya
 

Tendances (20)

Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Tracing in ASp.Net
Tracing in ASp.NetTracing in ASp.Net
Tracing in ASp.Net
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Math functions in javascript
Math functions in javascriptMath functions in javascript
Math functions in javascript
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.net
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Threads And Synchronization in C#
Threads And Synchronization in C#Threads And Synchronization in C#
Threads And Synchronization in C#
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Enterprise java unit-3_chapter-1-jsp
Enterprise  java unit-3_chapter-1-jspEnterprise  java unit-3_chapter-1-jsp
Enterprise java unit-3_chapter-1-jsp
 
RichControl in Asp.net
RichControl in Asp.netRichControl in Asp.net
RichControl in Asp.net
 

En vedette

En vedette (7)

Web Cookies
Web CookiesWeb Cookies
Web Cookies
 
Hypertext
HypertextHypertext
Hypertext
 
Presentation on Internet Cookies
Presentation on Internet CookiesPresentation on Internet Cookies
Presentation on Internet Cookies
 
Hypertext, hypermedia and multimedia
Hypertext, hypermedia and multimediaHypertext, hypermedia and multimedia
Hypertext, hypermedia and multimedia
 
Javascript
JavascriptJavascript
Javascript
 
Cookies PowerPoint
Cookies PowerPointCookies PowerPoint
Cookies PowerPoint
 
Cookies!
Cookies!Cookies!
Cookies!
 

Similaire à Cookie & Session In ASP.NET

Similaire à Cookie & Session In ASP.NET (20)

Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servlets
 
Cookies and Session
Cookies and SessionCookies and Session
Cookies and Session
 
murach12.pptx
murach12.pptxmurach12.pptx
murach12.pptx
 
07 cookies
07 cookies07 cookies
07 cookies
 
Sessions&cookies
Sessions&cookiesSessions&cookies
Sessions&cookies
 
Cache
CacheCache
Cache
 
Session tracking In Java
Session tracking In JavaSession tracking In Java
Session tracking In Java
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanism
 
Cookies in Angular | Install CookiesService
Cookies in Angular | Install CookiesServiceCookies in Angular | Install CookiesService
Cookies in Angular | Install CookiesService
 
FP512 Cookies sessions
FP512 Cookies sessionsFP512 Cookies sessions
FP512 Cookies sessions
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erick
 
Session and state management
Session and state managementSession and state management
Session and state management
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
SessionTrackServlets.pptx
SessionTrackServlets.pptxSessionTrackServlets.pptx
SessionTrackServlets.pptx
 
ASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and CookiesASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and Cookies
 
ASP.Net Presentation Part3
ASP.Net Presentation Part3ASP.Net Presentation Part3
ASP.Net Presentation Part3
 
Sessions n cookies
Sessions n cookiesSessions n cookies
Sessions n cookies
 
Servlet session 10
Servlet   session 10Servlet   session 10
Servlet session 10
 
C# cookieless session id and application state
C# cookieless session id and application stateC# cookieless session id and application state
C# cookieless session id and application state
 

Dernier

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Dernier (20)

Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 

Cookie & Session In ASP.NET

  • 1. PRESENTATION ON COOKIE AND SESSION MANAGEMENT IN ASP .NET Submitted To: Rachana Kamaliya Prepared By: Kumbhani Minaxi Limbasiya Jignasha
  • 2. INDEX  Introduction  Overview of Session  Session – Property/Method  Session - Example  Session Configuration  Advantages And Disadvantages Of Session  Overview Of Cookie  How cookies Started?  Cookie - Property  Cookie – Example  Advantages And Disadvantages Of Cookie  Differences Between Session & Cookie  References jignasha & Minaxi 1 Session & Cookie
  • 3. BASIC ABOUT STATE MANAGEMENT  ASP.NET framework provides various ways to preserve the states at various stage.  controlstate, viewstate, cookies, session, etc.  These can be defined at the client side and server side state management jignasha & Minaxi 3 Session & Cookie
  • 4. STATE MANAGEMENT jignasha & Minaxi 4 Session & Cookie
  • 5. OVERVIEW OF SESSION  Session is server side object.  It is saving your data for the session you are using the site.  There is a time for which this objects stay in the memory.  Session is defined in Web.Config for session state section otherwise 20 mins by default. jignasha & Minaxi 5 Fig : For every client session data store separately Session & Cookie
  • 6. SESSION  The Session is active:  Till the user closes the browser or  A certain period expires (20 minutes )  Every session is identified by a unique SessionID  Created at first entry in the site  Transmitted in a cookie by default jignasha & Minaxi 6 Session & Cookie
  • 7. PROPERTY jignasha & Minaxi 7 Property Description Count Gives the number of session variables which are in memory. Session ID Give you unique SessionID,which is assign to your session. TimeOut Get or Set TimeOut period. IsNewSession A Boolean value specifies whether session is new or old one. IsCookieLess A Boolean value specifies whether session is Cookless or not. Keys A collection of all keys Session & Cookie
  • 8. METHOD jignasha & Minaxi 8 Method Description Session.Remove (StrSessionName) Remove an Item from session state collection. Session.RemoveAll() Remove all Items from session collection. Session.Clear() There is no difference between clear and RemoveAll().RemoveAll() calls Clear().internally. Session & Cookie
  • 9. SESSION - EXAMPLE  Session Declaration:  Session Retriving:  Session Removing:  To handle events fired when a session is started or ended we use Session_OnStart and Session_OnEnd in the Global.asax file jignasha & Minaxi 9 Session["username"] = "pesho"; string = Session["username"].ToString(); Session.Remove(“username"); or Session[“username"] = null; Session & Cookie
  • 10. SESSION CONFIGURATION  We can configure various aspects of the session mechanism  Use the sessionState section in Web.config  Example: jignasha & Minaxi 10 <system.web> <sessionState cookieless="true" mode="InProc" timeout="60" cookieName="MySite" /> </system.web>  To deny/restrict access to the session <%@ Page EnableSessionState="False"%> <%@ Page EnableSessionState="ReadOnly" %> Session & Cookie
  • 11. ADVANTAGES & DISADVANTAGES Advantages:  Session provide us the way of maintain user data to all over the application.  session is that we can store any kind of object in it. :eg, database, dataset.. Etc  Session is secure and transparent from the user. Disadvantages:  Performance overhead in case of large volumes of user, because session data is stored in server memory. jignasha & Minaxi 11 Session & Cookie
  • 12. OVERVIEW OF COOKIES  Cookies are the small files that are created on the client's system or client browser memory.  We can store small pieces of information in a client system and use it when needed.  It works transparently with the user.  It can be easily used anywhere in your web application jignasha & Minaxi 12 Session & Cookie
  • 13. HOW COOKIE STARTED? jignasha & Minaxi 13 Session & Cookie
  • 14. HOW COOKIE STARTED?(CONT..) jignasha & Minaxi 14 Session & Cookie
  • 15. PROPERTY Property Description Name Specify name of cookie Value Contains value of cookie Expires Get or Set expiration Date of cookie. Expired Informs you whether cookie is expired or not. Domain Specific domain can be specified,if cookie store in specific folder. Path Allows you to set or get path of cookie to be store. jignasha & Minaxi 15 Session & Cookie
  • 16. COOKIE - EXAMPLE  working with cookies, we need to use the namespace System.web.  Creating a cookie that will be sent to the client Web browser:  Reading a cookie received at the server: jignasha & Minaxi 16 HttpCookie cookie = new HttpCookie ("UserName", "bajivan"); Response.Cookies.Add(cookie); HttpCookie cookie = Request.Cookies["UserName"]; Session & Cookie
  • 17. ADVANTAGES & DISADVANTAGES Advantages:  It's very simple to use and implement.  Browser takes care of sending the 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 the number of cookies is 20. jignasha & Minaxi 17 Session & Cookie
  • 18. 1. Cookies can store only "string" data type 2. They are stored at Client side 3. Cookie is non-secure since stored in text format at client side 4. Only in few situations we can use cookies because of no security 1.Session can store any data type 2. These are stored at Server side 3. Session are secure because it is stored in binary format 4. For all condition /situations we can use sessions jignasha & Minaxi 18 DIFF BETWEEN COOKIES & SESSION Session & Cookie
  • 19. REFERENCES  http://www.codeproject.com  http://en.wikipedia.org  http://www.Tutorials.com jignasha & Minaxi 19 Session & Cookie
  • 20. 20