1- Given this code fragment that creates two cookies: Response.Cookies[\"street\
ID: 3679725 • Letter: 1
Question
1- Given this code fragment that creates two cookies:
Response.Cookies["street"].Value = "1600 Pennsylvania Avenue";
Response.Cookies["cityState"].Value = "Washington, D.C.";
2- Provide a code fragment that stores the two cookie values shown above in just one cookie instead of two. You must use two subkeys. Use this as the first line in your one-cookie code fragment:
HttpCookie cookie = new HttpCookie("address");
3- Provide two reasons why you might prefer using one cookie with two subkeys as opposed to using two separate cookies. (The answer is not in our book. Use the Internet.)
Explanation / Answer
This is to store 2 cookie values in 1 cookie
HttpCookie cookie = new HttpCookie("address");
cookie.Values["street"] = "1600 Pennsylvania Avenue";
cookie.Values["cityState"] = "Washington, D.C.";
It is better to use one cookies with 2 subkeys instead of 2 serperate cookies because:
1)Basically the cookies are usually limited to 4096 bytes and a result of this we cannot store more than 20 cookies per site. So by using a single cookie with subkeys, we can use use fewer of those 20 cookies that outsite is allotted.
2.Moreover a single cookie takes up about 50 characters for overhead (expiration information) plus the length of the value that we store in it, all of which counts toward the 4096-byte limit. If we store six subkeys instead of six separate cookies, we can save the overhead of the separate cookies and can save around 200 bytes.This leads to less memory occupancy and the program can run faster due to less overheads.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.