The ASP.NET MVC segment is null. Session Variables Not Set

I have the following code in my Global.asax

protected void Application_AcquireRequestState(object sender, EventArgs e) { if (HttpContext.Current.Handler is IRequiresSessionState) { if (Request.IsAuthenticated) { if (HttpContext.Current.Session[this.MemberShipProvider.PrincipalSessionKey] != null) { CxPrincipal principal; try { principal = (CxPrincipal)HttpContext.Current.Session[this.MemberShipProvider.PrincipalSessionKey]; } catch { principal = null; } HttpContext.Current.User = principal; Thread.CurrentPrincipal = principal; } else { var identity = new CxIdentity("admin", 1, "", true); CxPrincipal principalLogin = new CxPrincipal(identity, 1); HttpContext.Current.Session[this.MemberShipProvider.PrincipalSessionKey] = principalLogin; HttpContext.Current.Session[SessionName.CurrentUser] = "Admin User"; HttpContext.Current.User = principalLogin; Thread.CurrentPrincipal = principalLogin; this.FormServiceProvider.SignIn("admin", false); // this is equal to FormsAuthentication.SetAuthCookie } } } } 

The problem is that every time Session is an object, the value is null. Not only here, I cannot use sessions in my application either. Either a Reset session, or something like that.

My application no longer requires a login. Therefore, I do not use Session.Clear or Session.Abandon anywhere in my application.

Please help me why my session variable is not set?

+6
source share
1 answer

You need to implement (and mb leave empty) 2 methods in global.asax.cs :

  void Session_Start(object sender, EventArgs e) { } void Session_End(object sender, EventArgs e) { } 
+3
source

Source: https://habr.com/ru/post/980928/


All Articles