session and cookies,get and post

29

Upload: baabtracom-no-1-supplier-of-quality-freshers

Post on 04-Jul-2015

160 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Session and cookies,get and post
Page 2: Session and cookies,get and post

Muhammed Ajmal I K

[email protected]

www.facebook.com/ajuik2008

twitter.com/mhdajmalik

in.linkedin.com/in/profilename

9745020951

Session and Cookies,

Get and Post

Page 3: Session and cookies,get and post

Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd

Page 4: Session and cookies,get and post

Overview

• Introduction

• State Management

• Cookie

• Session

• Get

• Post

Page 5: Session and cookies,get and post

Introduction

• Web Pages developed in ASP.Net are HTTP based

and HTTP protocol is a stateless protocol.

Page 6: Session and cookies,get and post

State Management

• It is the process by which you maintain state and page

information over multiple requests for the same or

different pages.

• Two type State Management

1. Client side State Management

Data can be stored at client side.

Ex: View state, Cookies , Query strings.

2. Server side State Management

Data can be stored at Server side.

Ex: Session state.

Page 7: Session and cookies,get and post

Cookie

Page 8: Session and cookies,get and post

Introduction

• Cookies are the small text files that are stored on

client side.

• It is used for state management.

• Used to send data from one webform to another.

Page 9: Session and cookies,get and post

How to create Cookies

Step 1: Create the cookie object

HttpCookie cookie = new HttpCookie("UserDetails");

Step 2: store value into cookie

cookie["Name"] = txtName.Text;

cookie["Email"] = txtEmail.Text;

Step 3: Add the cookie to the client machine

Response.Cookies.Add(cookie);

Page 10: Session and cookies,get and post

How to read data from Cookies

Step 1: Retrieve Cookie

HttpCookie cookie = Request.Cookies["UserDetails"];

Step 2: check whether a cookie was found or not.

if (cookie != null)

{

lblName.Text = cookie["Name"];

lblEmail.Text = cookie["Email"];

}

EXAMPLE

Page 11: Session and cookies,get and post

Types Of Cookie

• Cookies can be broadly classified into 2 types

1. Non-Persistent cookies

• Temporary Cookies.

• Remain in memory until the browser is closed.

2. Persistent cookies

• permanent cookies

• Remain on the client computer, even after the browser

is closed.

Page 12: Session and cookies,get and post

How to make persistent Cookies?

• persistent cookies should have an expatriation time

defined.

– cookie.Expires = DateTime.Now.AddDays(30);

Page 13: Session and cookies,get and post

Advantages and Disadvantages

of Cookies

• Advantages

– It's very simple to use and implement.

– Browser takes care of sending the data.

• Disadvantages

– It stores data in simple text format, so it's not

secure at all.

– There is a size limit for cookies data (4KB).

Page 14: Session and cookies,get and post

Session

• Session state variables are stored on the web server

• Session state is maintained per user basis in ASP .Net

runtime.

• Default life time is 20 minute.

Page 15: Session and cookies,get and post

Storing values To Session

• Use session Object

– Session["UserName"] = txtUser.Text;

Page 16: Session and cookies,get and post

Retrieving values From Session

Check weather session variable null or not

if (Session["UserName"] != null)

{

// Retrieving UserName from Session

lblWelcome.Text = "Welcome : " + Session["UserName"];

}

else

{ //Do Something }

Page 17: Session and cookies,get and post

Advantages and Disadvantages

of Session• Advantages

– Stores client data separately.

– Session is secure and transparent from the user.

• Disadvantages

– Performance overhead

Page 18: Session and cookies,get and post

Get and Post

Page 19: Session and cookies,get and post

Hypertext Transfer Protocol

• Http is the most common protocol used for

communication between a web server and a client.

• The 2 most commonly used HTTP methods are

1. GET

2. POST.

Page 20: Session and cookies,get and post

GET Request

• the data being sent to your server is coded into the

URL.

Page 21: Session and cookies,get and post

POST Request

• Data will be arranged in HTTP message body.

Page 22: Session and cookies,get and post

where it is?

• <form method="get||post">

• By default Get method are used

• If the form data is large then best is use POST

• By default the form with runat="server", will

have method="post“

Page 23: Session and cookies,get and post

where it is? Contd..

• the first request of that page: Request is a GET type .

• In postback: Request is a POST type

Page 24: Session and cookies,get and post

Difference between GET and POST

method

Page 25: Session and cookies,get and post

Example Programs….

if(Request.RequestType=="GET")

{

Response.Write("Request is a GET type");

}

else if(Request.RequestType=="POST")

{

Response.Write("Request is a POST type");

}

Page 26: Session and cookies,get and post

Thank You

Page 27: Session and cookies,get and post

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 designedto make a quick, good software professional out of anybody who holds a passion for coding.

Page 28: Session and cookies,get and post

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

Thanks in advance.

www.baabtra.com | www.massbaab.com |www.baabte.com

Page 29: Session and cookies,get and post

Contact Us

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Cafit Square,Hilite Business Park,Near Pantheerankavu,Kozhikode

Start up VillageEranakulam,Kerala, India.

Email: [email protected]