系统统一验证(IHttpHandlerFactory)<转>

代码
public class ValidateHttpHandlerFactory : IHttpHandlerFactory, IReadOnlySessionState
{
    #region IHttpHandlerFactory 成员

    public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
    {
        PageHandlerFactory factory 
= (PageHandlerFactory)Activator.CreateInstance(typeof(PageHandlerFactory), true);
        IHttpHandler handler 
= factory.GetHandler(context, requestType, url, pathTranslated);
        Page page 
= handler as Page;
        
if (page != null)
        {
            page.Init 
+= new EventHandler(page_Init);
        }
        
return handler;
    }

    public 
void ReleaseHandler(IHttpHandler handler)
    {

    }

    #endregion

    
void page_Init(object sender, EventArgs e)
    {
         
//这里来验证访问用户的合法性
        //Session
       //需要排除登录页面
    }

}
由于系统中是使用Session保存用户信息,所以在这里要访问Session需要继承IReadOnlySessionState接口。

如果还要写Session就需要继承IRequiresSessionState接口。

然后在web.config里面配置。

<httpHandlers>
    
<add path="*.aspx" verb="*" type="Hxj.Web.HttpHandlerFactory.ValidateHttpHandlerFactory,Hxj.Web.HttpHandlerFactory"/>
</httpHandlers>
这样就可以接管aspx页面,并且注册了Init 事件,来验证用户。

 

原文地址:http://www.cnblogs.com/huxj/archive/2010/05/22/1741799.html
posted @ 2010-07-15 10:18  温景良(Jason)  Views(304)  Comments(0Edit  收藏  举报