At the beginning of your custom module, you need to get a Session module and add an event handler for the Start event.
public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(Begin_Request); IHttpModule sessionModule = context.Modules["Session"]; if(sessionModule != null && sessionModule.GetType() == typeof(System.Web.SessionState.SessionStateModule)) { (sessionModule as System.Web.SessionState.SessionStateModule).Start += new EventHandler(CustomHttpModule_Start); } }
Also, can I write Global.asax aspure C # instead of using tags?
Yes, you can add the code behind in Global.asax and change the content to
<%@ Application Language="C#" CodeBehind="Global.asax.cs" Inherits="Global" %>
Your code behind should inherit from System.Web.HttpApplication
public class Global : System.Web.HttpApplication { public Global() { } void Session_Start(object sender, EventArgs e) {
source share