There is an event in your web application called Session_Start (in global.asax) that you can handle to know when a new session has started. Does this not work?
If it doesn't then, I suppose, you could write a trigger on the DB table. I don't think this is supported, but I'm sure it would work.
Session_Start is called when i have Session State Mode = InProc in web.config. for SQLServer this event is not fired
i know the stored procedure which is being called, but i want to do some changes in that, and for that i need to know that when exactly and from where exactly asp.net inserts values in ASPState DB
Session_Start is called when i have Session State Mode = InProc in web.config. for SQLServer this event is not fired
i know the stored procedure which is being called, but i want to do some changes in that, and for that i need to know that when exactly and from where exactly asp.net inserts values in ASPState DB
Umm, I knew Session_End didn't get called for our of proc session, but session_start should still get invoked.
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
if(Session.IsNewSession)
{
string sessionId = Session.SessionID;
Session["sessionID"] = sessionId;
}
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>
Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["sessionID"] != null)
{
Response.Write(Session["sessionID"].ToString());
//Session.Abandon();
}
}
}
And the msdn document just mentioneds the Session_OnEnd event is only supproted when the session mode is set to InProc, not talk about Session_OnStart event:
You can handle the Session_OnStart event by adding a subroutine named Session_OnStart to the Global.asax file. The Session_OnStart subroutine is run at the beginning of a request if the request begins a new session. A new session will be started if a request
is made that does not contain a SessionID value or if the SessionID property contained in the request references a session that has expired.
You can use the Session_OnStart event to initialize session variables as well as to track session-related information.
You can handle the Session_OnEnd event by adding a subroutine named Session_OnEnd to the Global.asax file. The Session_OnEnd subroutine is run when the Abandon method has been called or when the session has expired. A session expires when the number of minutes
specified by the Timeout property passes without a request being made for the session.
The Session_OnEnd event is supported only when the session state Mode property is set to InProc, which is the default. If the session state Mode is StateServer or SQLServer, then theSession_OnEnd event in the Global.asax file is ignored. If the session state
Mode is set to Custom, then support for the Session_OnEnd event is determined by the custom session-state store provider.
Please mark the replies as answers if they help or unmark if not.
Feedback to us
ok, that problem is solved on my side also which was related to firing Session_Start Event.
but what about my main problem, that i want to know that how i can get into more details about the architecutre of ASPState DB? i need to customize some columns and Information specially in tables which are there in ASPState DB?
ok, that problem is solved on my side also which was related to firing Session_Start Event.
So is your Session_Start now firing with Session Mode of SQLServer?
i.am.happy
but what about my main problem, that i want to know that how i can get into more details about the architecutre of ASPState DB? i need to customize some columns and Information specially in tables which are there in ASPState DB?
They document quite a bit of how it works
here, but the way I see it those database tables are private to the provider. You could always
implement your
own, or you could take the
code for the SQL Server one and modify it for your needs (which in essence is now a custom provider).
So is your Session_Start now firing with Session Mode of SQLServer?
Yes BrockAllen, actually on my local machine it is not working, but when i deploy it on Remote Machine, then it works...
don' t know what could be the reason.
any how, it seems difficult to "dive" into these providers and change any thing according to my requirements. :-(
Well , thanx for your links also, i will get into each topic in detail, and will try to implement some thing ...
i.am.happy
Member
32 Points
75 Posts
When Session Values are stored in ASPState DB????
May 27, 2012 02:23 PM|LINK
hi guys
i have an application in which i have Session Mode="SQLServer".
i need to ask that when asp.net inserts values for new session in table "ASPStateTempSessions"??? is there any event fired ????
Saalim bin Abdallah
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: When Session Values are stored in ASPState DB????
May 27, 2012 02:33 PM|LINK
There is an event in your web application called Session_Start (in global.asax) that you can handle to know when a new session has started. Does this not work?
If it doesn't then, I suppose, you could write a trigger on the DB table. I don't think this is supported, but I'm sure it would work.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
i.am.happy
Member
32 Points
75 Posts
Re: When Session Values are stored in ASPState DB????
May 27, 2012 02:49 PM|LINK
hi brockallen
Session_Start is called when i have Session State Mode = InProc in web.config. for SQLServer this event is not fired
i know the stored procedure which is being called, but i want to do some changes in that, and for that i need to know that when exactly and from where exactly asp.net inserts values in ASPState DB
Saalim bin Abdallah
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: When Session Values are stored in ASPState DB????
May 27, 2012 03:20 PM|LINK
Umm, I knew Session_End didn't get called for our of proc session, but session_start should still get invoked.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
i.am.happy
Member
32 Points
75 Posts
Re: When Session Values are stored in ASPState DB????
May 28, 2012 06:11 AM|LINK
no, session_start is not getting invoked if i set session mode= SQLserver, if i change it to InProc, then it gets invoked.......
there must be some provider for SQLserver state management through which we can handle the way ASP.net stores session in Data base....
Saalim bin Abdallah
i.am.happy
Member
32 Points
75 Posts
Re: When Session Values are stored in ASPState DB????
May 29, 2012 06:20 AM|LINK
guys, any solution to my question ????
Saalim bin Abdallah
Mamba Dai - ...
All-Star
23531 Points
2683 Posts
Microsoft
Re: When Session Values are stored in ASPState DB????
May 29, 2012 07:38 AM|LINK
Hi,
To determine whether the Session_OnStart event gets invoked under if the Session Mode to SQLServer. I create a simple web site to test.
The result is the Session_OnStart event does get invoked, and the Session_OnEnd event is never triggered:
My simple web site is below:
web.config file:
Global.asax:
<%@ Application Language="C#" %> <script runat="server"> void Application_Start(object sender, EventArgs e) { // Code that runs on application startup } void Application_End(object sender, EventArgs e) { // Code that runs on application shutdown } void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs } void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started if(Session.IsNewSession) { string sessionId = Session.SessionID; Session["sessionID"] = sessionId; } } void Session_End(object sender, EventArgs e) { // Code that runs when a session ends. // Note: The Session_End event is raised only when the sessionstate mode // is set to InProc in the Web.config file. If session mode is set to StateServer // or SQLServer, the event is not raised. } </script>Default.aspx.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["sessionID"] != null) { Response.Write(Session["sessionID"].ToString()); //Session.Abandon(); } } }And the msdn document just mentioneds the Session_OnEnd event is only supproted when the session mode is set to InProc, not talk about Session_OnStart event:
You can handle the Session_OnStart event by adding a subroutine named Session_OnStart to the Global.asax file. The Session_OnStart subroutine is run at the beginning of a request if the request begins a new session. A new session will be started if a request is made that does not contain a SessionID value or if the SessionID property contained in the request references a session that has expired.
You can use the Session_OnStart event to initialize session variables as well as to track session-related information.
You can handle the Session_OnEnd event by adding a subroutine named Session_OnEnd to the Global.asax file. The Session_OnEnd subroutine is run when the Abandon method has been called or when the session has expired. A session expires when the number of minutes specified by the Timeout property passes without a request being made for the session.
The Session_OnEnd event is supported only when the session state Mode property is set to InProc, which is the default. If the session state Mode is StateServer or SQLServer, then theSession_OnEnd event in the Global.asax file is ignored. If the session state Mode is set to Custom, then support for the Session_OnEnd event is determined by the custom session-state store provider.
Feedback to us
Develop and promote your apps in Windows Store
i.am.happy
Member
32 Points
75 Posts
Re: When Session Values are stored in ASPState DB????
May 30, 2012 10:10 AM|LINK
Thanks a lot "Mamba Dai - MSFT" for your reply
ok, that problem is solved on my side also which was related to firing Session_Start Event.
but what about my main problem, that i want to know that how i can get into more details about the architecutre of ASPState DB? i need to customize some columns and Information specially in tables which are there in ASPState DB?
Saalim bin Abdallah
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: When Session Values are stored in ASPState DB????
May 30, 2012 01:47 PM|LINK
So is your Session_Start now firing with Session Mode of SQLServer?
They document quite a bit of how it works here, but the way I see it those database tables are private to the provider. You could always implement your own, or you could take the code for the SQL Server one and modify it for your needs (which in essence is now a custom provider).
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
i.am.happy
Member
32 Points
75 Posts
Re: When Session Values are stored in ASPState DB????
May 30, 2012 03:16 PM|LINK
Yes BrockAllen, actually on my local machine it is not working, but when i deploy it on Remote Machine, then it works...
don' t know what could be the reason.
any how, it seems difficult to "dive" into these providers and change any thing according to my requirements. :-(
Well , thanx for your links also, i will get into each topic in detail, and will try to implement some thing ...
Saalim bin Abdallah