HttpContext.Current.Request.Cookies does not load value after reboot

I work on a multilingual C # website. I wrote databaselanguages โ€‹โ€‹class files and languages. In this class, I put all the lines in the appropriate language. By default, this language is Dutch if no cookie exists. Before I used the language class, I wrote it by default aspx.cs and requested a cookie as follows:

Context.Request.Cookies ["lancookie"]; 

If the language was changed, I changed the cookie and reloaded the page. In the language class, I use:

 HttpContext.Current.Request.Cookies ["lancookie"].Value; 

If I change the language, it will take several minutes before it also just boots up. What can I do to trigger a cookie?

  public class Language { public static string getLanCookie ()  {       lancookie string = string.Empty;       if (HttpContext.Current.Request.Cookies ["lancookie"]. Value! = null)       {           lancookie HttpContext.Current.Request.Cookies = ["lancookie"]. Value;       }       else       {           lancookie = "Dutch"; }       lancookie return; } public static string language = getLanCookie () public static string Home = Language ("Home", language);      public static string end = Language ("The End", language);      public static string Subject = Language ("Box", language); } 
+4
source share
1 answer

You have to use

HttpContext.Current.Response.Cookies

to install a new one. To clear the cookie, you will need to set an expiration date to be in the past. Will not go into details, as this should answer your question:

When to use Request.Cookies through Response.Cookies?

+2
source

All Articles