Reputation: 36733
How can I access a cookie in an MVC3 application?
It's for a shopping cart, where users can add an item to their cart, meaning to their cookie.
On checkout I would read this cookie for a key value pair of ProductId
and Quantity
for the appropriate price fetching from the database and calculation.
Very simply, how do I check for cookie and read/write data to them from a Controller action method?
Upvotes: 2
Views: 3173
Reputation: 35409
Read Cookie:
var cookie = Request.Cookies["key"];
Add Cookie:
Response.Cookies.Add(new System.Web.HttpCookie() { /* ... fill it up ... */ });
http://msdn.microsoft.com/en-us/library/ms525394(v=vs.90).aspx
Upvotes: 8