asp.net - Retrieving Session after login in MVC -


i want make shopping cart using session. use base controller assign new cart in session["cart"].

as expected, when go through different pages , go "cart" page, cart still exists products in it.

but log in, session null. how keep session alive after login, or assign previous session data new one?

my basecontroller class:

 protected override void initialize(requestcontext requestcontext)     {         base.initialize(requestcontext);         if(session["cart"] == null)         {             session["cart"] = new order();         }     } 

my global.asax file:

protected void application_start()     {         arearegistration.registerallareas();         filterconfig.registerglobalfilters(globalfilters.filters);         routeconfig.registerroutes(routetable.routes);         bundleconfig.registerbundles(bundletable.bundles);     }      protected void application_authenticaterequest()     {         if (httpcontext.current.user != null)         {             if (httpcontext.current.user.identity.isauthenticated)             {                 if (httpcontext.current.user.identity formsidentity)                 {                     var id = (formsidentity)httpcontext.current.user.identity;                     var ticket = (id.ticket);                     ticket = formsauthentication.decrypt(id.ticket.name);                      if (!string.isnullorempty(ticket.userdata))                     {                         string userdata = ticket.userdata;                         string[] roles = userdata.split(',');                         httpcontext.current.user = new system.security.principal.genericprincipal(id, roles);                     }                 }             }         }     }      protected void session_start(object sender, eventargs e)     {      }      protected void session_end(object sender, eventargs e)     {      } 

i feel there in global.asax file, don't quite know what. help!


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -