标签:
//集成IRequiresSessionState和IReadOnlySessionState是为了在类中访问session
public class ModuleBase : IHttpModule,IRequiresSessionState,IReadOnlySessionState
{
//Dispose():它可以在进行垃圾回收之前进行一些清理工作。
public void Dispose()
{
}
//Init():这个方法接受一个HttpApplication对象,HttpApplication代表了当前的应用程序,我们需要在这个方法内注册 HttpApplication对象暴露给客户端的事件。可见,这个方法仅仅是用来对事件进行注册,而实际的事件处理程序,需要我们另外写方法。
public void Init(HttpApplication context)
{
context.AcquireRequestState+=new EventHandler(context_AcquireRequestState);
}
void context_AcquireRequestState(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
if (application.Session == null || application.Session[SessionMarking] == null)
{
application.Response.Redirect(LoginUrl + "?ReturnUrl=" + HttpContext.Current.Request.RawUrl);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
return;
}
参考:http://www.cnblogs.com/zengen/articles/1184731.html;http://www.cnblogs.com/yuanyuan/archive/2010/11/15/1877709.html
标签:
原文地址:http://www.cnblogs.com/taikongbai/p/4414883.html