session-variables
Session variable value is getting null in ASP.NET Core
For ASP.NET Core 2.1 and 2.2 In the ConfigureServices method of the Startup class, Set options.CheckConsentNeeded = context => false; as follows: services.Configure<CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => false; options.MinimumSameSitePolicy = SameSiteMode.None; }); Problem solved!
What is the right time for ViewData, ViewBag, Session, TempData
ViewData/ViewBag – valid only for the duration of the current request. You set it in a controller action and use it in the view, then it disappears. The difference is that the first is a dictionary whereas the second is just a dynamic wrapper around this dictionary. Both point to the same data though. ViewBag …
HttpContext.Current.Session is null when routing requests
Got it. Quite stupid, actually. It worked after I removed & added the SessionStateModule like so: <configuration> … <system.webServer> … <modules> <remove name=”Session” /> <add name=”Session” type=”System.Web.SessionState.SessionStateModule”/> … </modules> </system.webServer> </configuration> Simply adding it won’t work since “Session” should have already been defined in the machine.config. Now, I wonder if that is the usual thing …
Are there limits for session variables?
As @Thariama said, there’s no limit on the number of variables; also, there’s no limit on the amount of data you can store in a session (I’ve seen sessions tens of MB in size). As the size of a session gets larger, you’ll run into various quirks though: PHP 5 deserializes the whole session into …
Is there a best practice and recommended alternative to Session variables in MVC
You will never get unanimous opinion on anything in any large group of people. That’s just human nature. Part of that stems from the Dunning-Kruger Effect which states that the less someone knows about a subject, the more likely they are to over value their expertise in that subject. In other words, lots of people …
ASP.NET removing an item from Session?
Is there a difference? There is. Session.Remove(key) deletes the entry (both key & value) from the dictionary while Session[key] = null assigns a value (which happens to be null) to a key. After the former call, the key won’t appear in the Session#Keys collection. But after the latter, the key can still be found in …
When should I use session variables instead of cookies?
Sessions are stored on the server, which means clients do not have access to the information you store about them. Session data, being stored on your server, does not need to be transmitted in full with each page; clients just need to send an ID and the data is loaded from the server. On the …