I've done quite a bit of testing on this, and I'm thoroughly confused. It seems ASP.NET will generate an ASP.NET_SessionId
cookie if the Session_Start
method in the MvcApplication
class is defined, even if I'm not using the Session
variable anywhere. That seems odd, considering there doesn't have to be anything in the 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() { } // this is all it takes to generate a SessionId (?)
}
}
Now, I'm confused for multiple reasons:
How is the mere presence of the
Session_Start
function enough to generate a SessionId? I'm not utilizing theSession
variable anywhere in the application, and the method is empty.The
Session_Start
method is private, and I'm obviously not calling it anywhere inside the class, so how does ASP.NET know when a session starts?How does anything outside of this class even know the
Session_Start
method exists, and to check for a SessionId cookie? It isn't a partial class, and it's explicitly markedprivate
.
I know these reasons sort of blend into one another, but I'm really at a loss as to how this works.