views:

382

answers:

3

what is the difference between asp cookie and javascript cookie. by asp cookie i mean cookie created using response.cookie & which one is better ?

+1  A: 

I think there is no difference at all?

Lalit
+1  A: 

Cookies are controlled by two HTTP protocol headers - Cookie and Set-Cookie. Cookie header is used in HTTP requests and Set-Cookie header is used in HTTP resonses. Response.Cookie represents Set-Cookie header while in javascript you mainly control internal collection of cookies collection which (collection) is used for Cookie header population for the following HTTP requests.

Vitaliy Liptchinsky
+1  A: 

There isn't a difference in the underlying "cookie" itself, only the approach to setting/reading it. Both are, in fact, a client-side cookie sent to and from the browser in the request/response headers.

The difference is that the cookie can be manipulated on the client in javascript (e.g. using document.cookie) or on the server from within ASP.NET (e.g. using Request.Cookies and Response.Cookies).

In fact, you could mix both ASP.NET and Javascript cookie manipulation on the same cookie if you really wanted to.

[BTW - I assume you were referring to ASP.NET. ALthough you only say ASP in your question text, the question is tagged as ASP.NET]

Rob Levine