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.
# 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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With