I joined this site today, hoping that someone would be kind enough to explain to me what I'm doing wrong with cookies in ASP.NET. I still study such apolig if my question is too simple, but I can not find the answer on google. Every answer I find shows a code that I already have.
I am experimenting with creating and reading cookies, I put this code in my application builder. this is how i try to initialize my cookie and add it to the browser.
Global.asax.cs
public MyApplication() { myCookie = new HttpCookie("UserSettings"); myCookie.Value = "nl"; myCookie.Expires = DateTime.Now.AddDays(1d); Response.Cookies.Add(myCookie); }
method in HomeController.cs (attempt to read a cookie)
public void setLang(string lang) { HttpCookie myCookie = Request.Cookies["UserSettings"]; myCookie.Value = lang;
I get the error Response.Cookies.Add (myCookie); [HttpException (0x80004005): The response is not available in this context.]
My thought is that I may have forgotten to import the namespace or something like that, but nothing seems to fix this error, can someone point me in the right direction?
source share