Hi All,
I have a custom IHttpModule which checks to see if a user is active on our intranet.
This is great and works well.
What I would like to do is also check the Session in the BeginRequest.... But it always comes back NULL.
What do I need to do so I can access Session values in the IHTTPModule ?
Any help greatly appreciated.
Regards
Andrew
PS. If the user is on a page I have some values Session["token"] for example that I would like
to check and react to in the BeginRequest.
public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(BeginRequest);
}
private void BeginRequest(object sender, EventArgs e)
{
HttpApplication app = ((HttpApplication)sender);
HttpContext context = app.Context;
string ip = SiteUtils.GetIP4Address();
try
{
if (IsActiveUser(ip)) return;
}
catch (DbException ex)
{
log.Error("handled exception: ", ex);
}
catch (InvalidOperationException ex)
{
log.Error("handled exception: ", ex);
}
log.Info(string.Format("Attempting page redirect: {0} for {1}",loginPage,ip));
context.RewritePath(loginPage);
}
private bool IsActiveUser(string ip)
{
// Check the ActiveUser Database and return True or False
return db.ActiveUsers.Where(qry => qry.IpAddress.Equals(ip)).Count() > 0;
}
public void Dispose() { }