例如判断Session是否为空,空则跳转

解决方案 »

  1.   

    用Httpmodule省事一些,不用每个页面继承
      

  2.   

    使用Httpmodule,效率更高,还能执行其他操作
    class AuthenticModule:IHttpModule
                    {
                        public void Dispose(){}
                        public void Init(HttpApplication context)
                        {
                            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
                        }
                        void context_PreRequestHandlerExecute(object sender, EventArgs e)
                        {
                            HttpApplication ha = (HttpApplication)sender;
                            string path = ha.Context.Request.Url.ToString();
                            int n = path.ToLower().IndexOf("Login.aspx"); 
                            if (n == -1) 
                            {
                               if (ha.Context.Session["user"] == null)                     {
                                    ha.Context.Response.Redirect("Login.aspx?source=" + path);
                                }
                            }
                        }
                    } 
    }
    参考
      

  3.   

    HttpModule好些,是他是从上到下循序执行,每次请求都回执行Module
      

  4.   

    basepage也不是一无是处好不好, 如果某些带功能性的相似页面,用basepage是可以节约大量代码的.不过了解一下httpmodule也好.
      

  5.   

    常用BasePage,有必要搞个httpmodule吗?
      

  6.   

    没有绝对没有前提的,就是你喜欢用哪个就用哪个难度上说,特别如果你不熟 asp.net 声明周期,你还是用 基类页面吧