c# - How does ASP.NET know to create the ASP.NET_SessionId cookie if Session_Start is defined? -


i've done quite bit of testing on this, , i'm thoroughly confused. seems asp.net generate asp.net_sessionid cookie if session_start method in mvcapplication class defined, if i'm not using session variable anywhere. seems odd, considering there doesn't have in method's body.

example (global.asax.cs):

using system.web.mvc; using system.web.optimization; using system.web.routing;  namespace myapplication {     public class mvcapplication : system.web.httpapplication     {         protected void application_start()         {             arearegistration.registerallareas();             filterconfig.registerglobalfilters(globalfilters.filters);             routeconfig.registerroutes(routetable.routes);             bundleconfig.registerbundles(bundletable.bundles);         }          private void session_start() { } // takes generate sessionid (?)     } } 

now, i'm confused multiple reasons:

  1. how mere presence of session_start function enough generate sessionid? i'm not utilizing session variable anywhere in application, , method empty.

  2. the session_start method private, , i'm not calling anywhere inside class, how asp.net know when session starts?

  3. how outside of class know session_start method exists, , check sessionid cookie? isn't partial class, , it's explicitly marked private.

i know these reasons sort of blend 1 another, i'm @ loss how works.

session_start event handler application. when new session created, method called application. not create session ids, meant way developer know when user visits site first time (that session). can used run initialization routines or tracking purposes (e.g., had x number of unique sessions today).

what triggers creation of session , sessionid user visiting page has session enabled-- asp.net create session behind scenes. answer question has 2 ways of enabling session state pages: session state can used when enablesessionstate set true either in configuration

in summary:

in web.config, pages:

<system.web>       <pages enablesessionstate="true" />   </system.web> 

in page.aspx, on per-page basis (set false turn off on per-page basis):

<%@page enablesessionstate="true">  

your web.config should configure sessionstate mode. example of using server's memory store session state:

<sessionstate cookieless="false" mode="inproc" timeout="20" /> 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -