Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 06, 2010 03:37 PM by khoailang
Oct 19, 2009 01:06 PM|LINK
I want to pre populate some of the form fields from browser cookies on the mvc website. How can I do that? How to set and load cookies in an mvc app?
Oct 19, 2009 01:38 PM|LINK
In the same way as in another ASP.NET application - via Cookies property on
Request and Response objects. These objects are accessible from controller via
HttpContext.Request and HttpContext.Response properties. So just use
HttpContext.Request.Cookies and HttpContext.Response.Cookies from your controller.
Oct 20, 2009 12:35 PM|LINK
Yeah but how do i pre-populate the field? Example if a user clicks "Remember my username" on the login form, I want to store the name in a cookie and prefill it next time the user visits the form. I can create and retrive a cookie but not sure how to pre
fill the username field.
Oct 20, 2009 12:45 PM|LINK
Just store username into HttpContext.Response.Cookies collection and when you are preparing data for showing login form then read
username from HttpContext.Request.Cookies.
Oct 20, 2009 02:03 PM|LINK
How to read data and show on screen? any code snippet?
Oct 20, 2009 09:21 PM|LINK
bump.. kinda urgent :(
Oct 21, 2009 06:48 AM|LINK
Please refer to the following code to display the cookie .
And we can use the following code to add a cookie.
public ActionResult Index()
HttpCookie hc = new HttpCookie("test","123");
Nov 06, 2010 03:37 PM|LINK
hi, just a quick query please
It appears cookies does not persist in localhost server, does it? (using built in server of VS)
I did set start up url as www.abc.com in my solution setting and my IE also has cookies setting enabled.
Please advise how can I have cookies work in localhost testing server?