Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What actually causes Session_Start to be called?

In a little demo application that I'm building I put code to initialize the database in the Global.Session_Start() event. However, I notice that this event does not fire when I'm running through the app in the debugger on the development server (haven't tested it anywhere else yet).

Question 1: What gives? When does Session_Start() actually get called? I assume it is when the session starts but shouldn't the beginning of every new sequence of requests cause a session to start automatically? Certainly a session should start whenever I run with F5 so why doesn't it.

Question 2: Is there a better place where the code to initialize the database should go? i would rather not put it in the Application_Start method, since it does not always get called when debugging.

PS. By initialize database I do not mean I open a connection to SqlServer and leave it open forever. I am using db4o and I open a pre-built database file. Like I said this is just a demo application, I'm not worried about poor resource management or anything like that.

like image 225
George Mauer Avatar asked Mar 22 '09 14:03

George Mauer


People also ask

When session_start is called in asp net?

# Session_Start: Fired when a new user visits the application Website. # Session_End: Fired when a user's session times out, ends, or theyleave the application Web site.

When the session_ start() function is called?

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie. When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers.

Why use session_ start()?

Sessions or session handling is a way to make the data available across various pages of a web application. The session_start() function is used to start a new session or, resume an existing one.

Where must the session_start () function appear in PHP?

The important thing is that the session_start function must be called at the beginning of the script, before any output is sent to the browser.


1 Answers

I know this is an old post but maybe this will help somebody:

The session_start doesn't fire unless you are actually reading or writing to the session object.

If you want to utilize the session_start event but don't need to use the session store at all, you can add the following to the page directive of your landing pages:

<%@ Page EnableSessionState="ReadOnly" %>

This will cause the session_start event to fire without you having to store anything in the session object.

like image 136
George Filippakos Avatar answered Sep 20 '22 21:09

George Filippakos