3. Introduction
Web appcation work on HTTPprotocol
HTTP protocol is a stateless protocol
It does not maintain the state between
requests
4. cookies
• A cookie is often used to identify a user.
• A cookie is a small file that the server embeds
on the user's computer.
• Common use of cookies is to remember users
between visits.
5. Uses of cookies
• Identification of a user session, user's
preferences.
• Cookies can also be used for travelling of data
from one page to another.
• Shopping cart contents
• Authentication
7. By using HttpCookies class
HttpCookie StudentCookies = new HttpCookie("StudentCookies");
StudentCookies.Value = TextBox1.Text;
StudentCookies.Expires = DateTime.Now.AddHours(1);
Response.Cookies.Add(StudentCookies);
8. By using Response directly
Response.Cookies["StudentCookies"].Value = TextBox1.Text;
Response.Cookies["StudentCookies"].ExpiresDateTime.Now.AddDays(1)
;
9. multiple values in same cookie
Response.Cookies["StudentCookies"]["RollNumber"] = TextBox1.Text;
Response.Cookies["StudentCookies"]["FirstName"] = "Anu";
Response.Cookies["StudentCookies"]["LastName"] = "Menon";
Response.Cookies["StudentCookies"].Expires =
DateTime.Now.AddDays(1);
10. How to Retrieve a Cookie Value?
For httpcookie class and response directly
method:
string val = Request.Cookies["StudentCookies"].Value;
For multiple cookies:
string val;
val = Request.Cookies["StudentCookies"]["RollNumber"];
val= val+ " " + Request.Cookies["StudentCookies"]["FirstName"];
val = val+ " " +Request.Cookies["StudentCookies"]["LastName"];
Label1.Text = val;
12. Deleting cookies
For deleting cookies:
if (Request.Cookies["StudentCookies"] != null)
{
Response.Cookies["StudentCookies"].Expires =
DateTime.Now.AddDays(-1);
}
13. session
Session serve the same purpose of cookies
that is sessions are used to maintain the state
in between requests
18. Difference between session and
cookies
cookies session
cookies are stored in the user's browser Sessions are stored in server
A cookie can keep information in the user's
browser until deleted by user or set as per the
timer. It will not be destroyed even if you
close the browser.
A session is available as long as the browser is
opened. Usercant disable the session. It will
be destroyed if you close the browser
Cookies can only store string Can store any object
we can save cookie for future reference Session can’t be.
19. HTTP methods
HTTP methods is used for send the data from
client side to server side.
GET METHOD
POST METHOD
20. comparison
GET METHOD POST METHOD
Data will be arranged in HTTP header by
appending to the URL as query string
Data will be arranged in HTTP message body.
Data is in query string so user can view the
data
Data is not shown to user
Less secured compared to POST method
because data is in query string so it will be
saved in browser history and web server logs
safer than GET method because data is not
saved in history or web server logs.
As data is saved in URL so its saves only 2048
bytes data
We can used any amount of data and any
format
Hacking will be easy Hacking is difficult
Only ASCII character data type allowed No restrictions. Allows binary data also
21. 21
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
22. Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
23. Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
24. Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us