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!

PHP session side-effect warning with global variables as a source of data

basically you have a variable with the same name as your session. ex: $_SESSION[‘var1’] = null; $var1 = ‘something’; which will reproduce this error. you can stop PHP from trying to find existing variables and warning you about them by adding these lines to your script: ini_set(‘session.bug_compat_warn’, 0); ini_set(‘session.bug_compat_42’, 0); these values can be set … Read more

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 … Read more

How to access session variables from any class in ASP.NET?

(Updated for completeness) You can access session variables from any page or control using Session[“loginId”] and from any class (e.g. from inside a class library), using System.Web.HttpContext.Current.Session[“loginId”]. But please read on for my original answer… I always use a wrapper class around the ASP.NET session to simplify access to session variables: public class MySession { … Read more

Session variables not working php

Make sure session_start(); is called before any sessions are being called. So a safe bet would be to put it at the beginning of your page, immediately after the opening <?php tag before anything else. Also ensure there are no whitespaces/tabs before the opening <?php tag. After the header redirect, end the current script using … Read more