What is the difference between cookies and session?

Answers were Sorted based on User's Feedback



What is the difference between cookies and session?..

Answer / aruna jyothi

Cookies
1. Cookies can store only "string" datatype
2. They are stored at Client side
3. Cookie is non-secure since stored in text format at
client side
4. Cookies may or may not be individual for every
client
5. Due to cookies network traffic will increase.Size
of cookie is limited to 40 and number of cookies to be used
is restricted to 20.
6. Only in few situations we can use cookies because
of no security
7. We can disable cookies
8. Since the value is string there is no security
9. We have persistent and non-persistent cookies

Session
1. Session can store any type of data because the
value is of datatype of "object"
2. These are stored at Server side
3. Session are secure because it is stored in binary
format/encrypted form and it gets decrypted at server
4. Session is independent for every client i.e
individual for every client
5. There is no limitation on size or number of
sessions to be used in an application
6. For all conditions/situations we can use sessions
7. we cannot disable the sessions.Sessions can be used
without cookies also(by disabling cookies)
8. The disadvantage of session is that it is a
burden/overhead on server
9. Sessions are called as Non-Persistent cookies
because its life time can be set manually

Is This Answer Correct ?    255 Yes 18 No

What is the difference between cookies and session?..

Answer / kishoreg

State Management in APS.NET is managed by two ways:
Client-Side or Server-Side

Client-Side:Cookies,HiddenFields,ViewState and Query
Strings.
Serve-Side:Application,Session and Database.

COOKIE:
A cookie is a small amount of data stored either in a text
file on the client's file system or in-memory in the client
browser session. Cookies are mainly used for tracking data
settings. Let’s take an example: say we want to customize a
welcome web page, when the user request the default web
page, the application first to detect if the user has
logined before, we can retrieve the user informatin from
cookies:
[c#]
if (Request.Cookies[“username”]!=null)
lbMessage.text=”Dear “+Request.Cookies[“username”].Value+”,
Welcome shopping here!”;
else
lbMessage.text=”Welcome shopping here!”;

If you want to store client’s information, you can use the
following code:
[c#]
Response.Cookies[“username’].Value=username;

So next time when the user request the web page, you can
easily recongnize the user again.

SESSION:
Session object can be used for storing session-specific
information that needs to be maintained between server
round trips and between requests for pages. Session object
is per-client basis, which means different clients generate
different session object.The ideal data to store in session-
state variables is short-lived, sensitive data that is
specific to an individual session.

Each active ASP.NET session is identified and tracked using
a 120-bit SessionID string containing URL-legal ASCII
characters. SessionID values are generated using an
algorithm that guarantees uniqueness so that sessions do
not collide, and SessionID’s randomness makes it harder to
guess the session ID of an existing session.
SessionIDs are communicated across client-server requests
either by an HTTP cookie or a modified URL, depending on
how you set the application's configuration settings.

Every web application must have a configuration file named
web.config, it is a XML-Based file, there is a section
name ‘sessionState’, the following is an example:

<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user
id=sa;password=" cookieless="false" timeout="20" />

‘cookieless’ option can be ‘true’ or ‘false’. When it
is ‘false’(default value), ASP.NET will use HTTP cookie to
identify users. When it is ‘true’, ASP.NET will randomly
generate a unique number and put it just right ahead of the
requested file, this number is used to identify users
[c#]
//to store information
Session[“myname”]=”Mike”;
//to retrieve information
myname=Session[“myname”];

this is briefly about cookies and sessions in ASP.NET

Is This Answer Correct ?    100 Yes 14 No

What is the difference between cookies and session?..

Answer / m.chenna krisha reddy

cookie:
1.cookie store client side
2.cookies can store only string type
3.cookies is non secure since stored text format at client side
4.there is limited size
session:
1.session store server side
2.session store any type of data because the value is of datatype of object
3.there is no limitation size
4.session is secure because it is stored in binary format

Is This Answer Correct ?    62 Yes 5 No

What is the difference between cookies and session?..

Answer / manoj kumar

1. Cookies can store only "string" datatype
2. They are stored at Client side
3. Cookie is non-secure since stored in text format at
client side
4. Cookies may or may not be individual for every
client
5. Due to cookies network traffic will increase.Size
of cookie is limited to 40 and number of cookies to be used
is restricted to 20.
6. Only in few situations we can use cookies because
of no security
7. We can disable cookies
8. Since the value is string there is no security
9. We have persistent and non-persistent cookies

Session
1. Session can store any type of data because the
value is of datatype of "object"
2. These are stored at Server side
3. Session are secure because it is stored in binary
format/encrypted form and it gets decrypted at server
4. Session is independent for every client i.e
individual for every client
5. There is no limitation on size or number of
sessions to be used in an application
6. For all conditions/situations we can use sessions
7. we cannot disable the sessions.Sessions can be used
without cookies also(by disabling cookies)
8. The disadvantage of session is that it is a
burden/overhead on server
9. Sessions are called as Non-Persistent cookies
because its life time can be set manually

Is This Answer Correct ?    36 Yes 5 No

What is the difference between cookies and session?..

Answer / ajay

State Management in APS.NET is managed by two ways:
Client-Side or Server-Side

Client-Side:Cookies,HiddenFields,ViewState and Query
Strings.
Serve-Side:Application,Session and Database.

COOKIE:
A cookie is a small amount of data stored either in a text
file on the client's file system or in-memory in the client
browser session. Cookies are mainly used for tracking data
settings. Let’s take an example: say we want to customize a
welcome web page, when the user request the default web
page, the application first to detect if the user has
logined before, we can retrieve the user informatin from
cookies:
[c#]
if (Request.Cookies[“username”]!=null)
lbMessage.text=”Dear “+Request.Cookies[“username”].Value+”,
Welcome shopping here!”;
else
lbMessage.text=”Welcome shopping here!”;

If you want to store client’s information, you can use the
following code:
[c#]
Response.Cookies[“username’].Value=username;

So next time when the user request the web page, you can
easily recongnize the user again.

SESSION:
Session object can be used for storing session-specific
information that needs to be maintained between server
round trips and between requests for pages. Session object
is per-client basis, which means different clients generate
different session object.The ideal data to store in session-
state variables is short-lived, sensitive data that is
specific to an individual session.

Each active ASP.NET session is identified and tracked using
a 120-bit SessionID string containing URL-legal ASCII
characters. SessionID values are generated using an
algorithm that guarantees uniqueness so that sessions do
not collide, and SessionID’s randomness makes it harder to
guess the session ID of an existing session.
SessionIDs are communicated across client-server requests
either by an HTTP cookie or a modified URL, depending on
how you set the application's configuration settings.

Every web application must have a configuration file named
web.config, it is a XML-Based file, there is a section
name ‘sessionState’, the following is an example:

<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user
id=sa;password=" cookieless="false" timeout="20" />

‘cookieless’ option can be ‘true’ or ‘false’. When it
is ‘false’(default value), ASP.NET will use HTTP cookie to
identify users. When it is ‘true’, ASP.NET will randomly
generate a unique number and put it just right ahead of the
requested file, this number is used to identify users
[c#]
//to store information
Session[“myname”]=”Mike”;
//to retrieve information
myname=Session[“myname”];

this is briefly about cookies and sessions in ASP.NET

Is This Answer Correct ?    12 Yes 2 No

What is the difference between cookies and session?..

Answer / kayal

The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not. A cookie can keep information in the user's browser until deleted. Sessions 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. I have read the very good post on cookies and sessions with suitable php code.You can see that on
http://cs-pages.blogspot.com/2011/05/difference-between-cookies-and-sessions.html

Is This Answer Correct ?    12 Yes 7 No

What is the difference between cookies and session?..

Answer / yogita mahajan

Cookies are some values saved in browsers for a particular website o publicly accessible
The purpose of cookies is to help websites to identify visitors and retrieve their saved preferences
Cookies are also used to facilitate auto login by persisting user id in a cookie save in user’s browser
Because cookies have been saved at client side, they do not create performance issues but may create security issues as they can be hacked from browser

Session variables are usually the most commonly used.
When a user visits a site, it’s sessions starts and when the user become idle or leave the site, the session ends.
Session variables should be used to save and retrive user specefic information required on multiple pages.
Session variables consumes server memory, so if your may have a huge amount visiters, use session very carefully and instead of put large values in it try to put IDs and references

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Sharp Interview Questions

what is the purpose of Interfaces?

7 Answers   HCL,


From a versioning perspective, what are the drawbacks of extending an interface as opposed to extending a class?

0 Answers  


Can hashtable have duplicate keys in c#?

0 Answers  


Difference between abstract classes and interfaces

0 Answers  


Can dictionary have duplicate keys c#?

0 Answers  






What is sqlconnection in c#?

0 Answers  


Explain About .NET Framework

0 Answers  


What do you mean by string objects are immutable?

0 Answers  


What?s the role of the DataReader class in ADO.NET connections?

2 Answers  


What is an enumerator in c#?

0 Answers  


When a new instance of a type is created, what is the type of method implicitly called?

2 Answers  


What is executescalar in c#?

0 Answers  


Categories