Sessions&cookies

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
1 de 10

Recomendados

Cookies in servlets.ppt por
Cookies in servlets.pptCookies in servlets.ppt
Cookies in servlets.pptSwetha S
205 vistas11 diapositivas
Protect Your System - Use Browser Junk Removal Tool por
Protect Your System - Use Browser Junk Removal ToolProtect Your System - Use Browser Junk Removal Tool
Protect Your System - Use Browser Junk Removal Toolstocksben
42 vistas6 diapositivas
APEX & Cookie Monster por
APEX & Cookie MonsterAPEX & Cookie Monster
APEX & Cookie MonsterChristian Rokitta
2K vistas22 diapositivas
Using cookies and sessions por
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessionsNuha Noor
1.2K vistas21 diapositivas
Caching idea for midcom por
Caching idea for midcomCaching idea for midcom
Caching idea for midcomtepheikk
363 vistas6 diapositivas
Cookies authentication por
Cookies authenticationCookies authentication
Cookies authenticationRsilwal123
166 vistas19 diapositivas

Más contenido relacionado

Similar a Sessions&cookies

Enterprise java unit-2_chapter-2 por
Enterprise  java unit-2_chapter-2Enterprise  java unit-2_chapter-2
Enterprise java unit-2_chapter-2sandeep54552
138 vistas18 diapositivas
Enterprise java unit-2_chapter-3 por
Enterprise  java unit-2_chapter-3Enterprise  java unit-2_chapter-3
Enterprise java unit-2_chapter-3sandeep54552
561 vistas21 diapositivas
Session and Cookies.pdf por
Session and Cookies.pdfSession and Cookies.pdf
Session and Cookies.pdfHamnaGhani1
2 vistas22 diapositivas
Cookies in servlet por
Cookies in servletCookies in servlet
Cookies in servletchauhankapil
170 vistas10 diapositivas
Session and cookies,get and post por
Session and cookies,get and postSession and cookies,get and post
Session and cookies,get and postbaabtra.com - No. 1 supplier of quality freshers
840 vistas29 diapositivas
E Commerce Analytics Demandware por
E Commerce Analytics DemandwareE Commerce Analytics Demandware
E Commerce Analytics Demandwareloripelletier
9.3K vistas17 diapositivas

Similar a Sessions&cookies(20)

Enterprise java unit-2_chapter-2 por sandeep54552
Enterprise  java unit-2_chapter-2Enterprise  java unit-2_chapter-2
Enterprise java unit-2_chapter-2
sandeep54552138 vistas
Enterprise java unit-2_chapter-3 por sandeep54552
Enterprise  java unit-2_chapter-3Enterprise  java unit-2_chapter-3
Enterprise java unit-2_chapter-3
sandeep54552561 vistas
Session and Cookies.pdf por HamnaGhani1
Session and Cookies.pdfSession and Cookies.pdf
Session and Cookies.pdf
HamnaGhani12 vistas
E Commerce Analytics Demandware por loripelletier
E Commerce Analytics DemandwareE Commerce Analytics Demandware
E Commerce Analytics Demandware
loripelletier9.3K vistas
Cookies and Session por KoraStats
Cookies and SessionCookies and Session
Cookies and Session
KoraStats303 vistas
Cookies testing por abhi2632
Cookies testingCookies testing
Cookies testing
abhi26323.1K vistas
Cookies: HTTP state management mechanism por Jivan Nepali
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanism
Jivan Nepali1.9K vistas
C# cookieless session id and application state por Malav Patel
C# cookieless session id and application stateC# cookieless session id and application state
C# cookieless session id and application state
Malav Patel399 vistas
Cookie & Session In ASP.NET por ShingalaKrupa
Cookie & Session In ASP.NETCookie & Session In ASP.NET
Cookie & Session In ASP.NET
ShingalaKrupa11.3K vistas
PHP COOKIES AND SESSIONS por Degu8
PHP COOKIES AND SESSIONSPHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONS
Degu820 vistas

Último

hamro digital logics.pptx por
hamro digital logics.pptxhamro digital logics.pptx
hamro digital logics.pptxtupeshghimire
10 vistas36 diapositivas
ATPMOUSE_융합2조.pptx por
ATPMOUSE_융합2조.pptxATPMOUSE_융합2조.pptx
ATPMOUSE_융합2조.pptxkts120898
35 vistas70 diapositivas
Affiliate Marketing por
Affiliate MarketingAffiliate Marketing
Affiliate MarketingNavin Dhanuka
18 vistas30 diapositivas
The Dark Web : Hidden Services por
The Dark Web : Hidden ServicesThe Dark Web : Hidden Services
The Dark Web : Hidden ServicesAnshu Singh
16 vistas24 diapositivas
How to think like a threat actor for Kubernetes.pptx por
How to think like a threat actor for Kubernetes.pptxHow to think like a threat actor for Kubernetes.pptx
How to think like a threat actor for Kubernetes.pptxLibbySchulze1
7 vistas33 diapositivas
Marketing and Community Building in Web3 por
Marketing and Community Building in Web3Marketing and Community Building in Web3
Marketing and Community Building in Web3Federico Ast
15 vistas64 diapositivas

Último(6)

ATPMOUSE_융합2조.pptx por kts120898
ATPMOUSE_융합2조.pptxATPMOUSE_융합2조.pptx
ATPMOUSE_융합2조.pptx
kts12089835 vistas
The Dark Web : Hidden Services por Anshu Singh
The Dark Web : Hidden ServicesThe Dark Web : Hidden Services
The Dark Web : Hidden Services
Anshu Singh16 vistas
How to think like a threat actor for Kubernetes.pptx por LibbySchulze1
How to think like a threat actor for Kubernetes.pptxHow to think like a threat actor for Kubernetes.pptx
How to think like a threat actor for Kubernetes.pptx
LibbySchulze17 vistas
Marketing and Community Building in Web3 por Federico Ast
Marketing and Community Building in Web3Marketing and Community Building in Web3
Marketing and Community Building in Web3
Federico Ast15 vistas

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

Notas del editor

  1. 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.