August 7, 2008

MOSS: Using Session_OnStart

Want to do something in Session_OnStart event in your MOSS web application? Modifying global.asax doesn't have any effect? Getting frustrated?

No worries, just create HttpModule like in the following example. In my code I'm creating a "WWW" cookie that is required by Load Balancer and setting cookie value from an appSettings key in web.config.

class NLBModule : IHttpModule
#region IHttpModule Members

public void Dispose()

public void Init(HttpApplication context)
SessionStateModule sessionModule = (SessionStateModule)context.Modules["Session"];

sessionModule.Start += delegate(object sender, EventArgs e) { sessionModule_Start(sender, e, context); };

void sessionModule_Start(object sender, EventArgs e, HttpApplication context)
context.Response.Cookies.Add(new HttpCookie("WWW", ConfigurationManager.AppSettings["NLB_ID"]));

Finally register the HttpModule in web.config like this:



<add name="NLBModule" type="MyProject.HttpHandlers.NLBModule, MyProject.HttpHandlers, Version=, Culture=neutral, PublicKeyToken=XYZ" />



No comments:

Post a Comment