what is the difference between asp cookie and javascript cookie. by asp cookie i mean cookie created using response.cookie & which one is better ?
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.
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]