I have a requirement to set up a number of session variables at the start of each session but cannot find a way to access the Session_Start function. There seems to be a lot of conflicting advice depending on the version being used. We are currently 4.6.2 and soon will be 4.7.1 and we have tried to inherit from Umbraco:Global but with no success.
I'm obviously missing something or cannot see the right thread. Can anybody point me in the right direction?
Amazing how explaining stuff to someone else helps you get a better handle on what you are doing.
To gain access to Session_Start in versions over 4.5 (maybe lower as well) simply delete the app_Global.asax.dll from the Bin folder. Add a global.asax to the project root, delete all the handlers except Session_Start and add inherits="umbraco.Global" to the header line, eg.
<%@ Application Language="C#" Inherits="umbraco.Global"%>
<script runat="server">
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session["test"] = "hello";
}
</script>
This works fine and allows us to set up and initialise session variables. I don't know what umbraco.Global does in the other handlers so I have deleted them from my version as it is only Session_Start I want access to and umbraco.Global doesn't use it.
It may be you can cover them by calling the base handlers first, eg.
<%@ Application Language="C#" Inherits="umbraco.Global"%>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Call Global base class first
base.Application_Start(sender, e);
// Bespoke code that runs when the application is started
Application["test"] = "hello";
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session["test"] = "hello";
}
</script>
I haven't tried this but it should work I think. I hope this is useful to others who have found quite a lot of conflicting material running across several versions.
Accessing the Session_Start function
Hi,
I have a requirement to set up a number of session variables at the start of each session but cannot find a way to access the Session_Start function. There seems to be a lot of conflicting advice depending on the version being used. We are currently 4.6.2 and soon will be 4.7.1 and we have tried to inherit from Umbraco:Global but with no success.
I'm obviously missing something or cannot see the right thread. Can anybody point me in the right direction?
Thanks
Roger
Hi Roger,
Quick check, have you deleted the "App_global.asax.dll" from the /bin directory? As that would be taking presidence.
For further reading, Matt Brailsford has a blog post about it: Registering an Application_Start Event Handler in Umbraco
Cheers, Lee
Hi Lee,
Amazing how explaining stuff to someone else helps you get a better handle on what you are doing.
To gain access to Session_Start in versions over 4.5 (maybe lower as well) simply delete the app_Global.asax.dll from the Bin folder. Add a global.asax to the project root, delete all the handlers except Session_Start and add inherits="umbraco.Global" to the header line, eg.
<%@ Application Language="C#" Inherits="umbraco.Global"%> <script runat="server"> void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started Session["test"] = "hello"; } </script>
This works fine and allows us to set up and initialise session variables. I don't know what umbraco.Global does in the other handlers so I have deleted them from my version as it is only Session_Start I want access to and umbraco.Global doesn't use it.
It may be you can cover them by calling the base handlers first, eg.
I haven't tried this but it should work I think. I hope this is useful to others who have found quite a lot of conflicting material running across several versions.
Regards
Roger
is working on a reply...