在js中
if('<%Session["abc"]%>' == null)
{
    window.location = "login.aspx";
}

解决方案 »

  1.   

    if(Session["value"]==null)
    {
    Response.Redirect("login.aspx");
    }
      

  2.   

    不知道在application里面加个数组监视行不行 ?
      

  3.   

    写个用户控件,在里面判断session的相关值是否为空,空则跳转。然后每个需要验证登录的页面扔一个,省事!
      

  4.   

    xht0832:具体怎么实现呢
    用户控件是怎样 的?
    需要验证登陆的页面扔个什么?
      

  5.   

    资源管理器中 项目 右键 添加,加入 用户控件 就是后缀名为.ascx的组件。然后他的CS文件里写控制代码:
    protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"]==null)
            {
                Response.Redirect("Login.aspx");
            }
        }
    前台页面不用写,写完后保存,每个需要的页面扔一个,由于前台什么都没写,所以运行时是看不到的
      

  6.   

    最好使用.net本事的form验证,web.config中设置   
      没有登陆则跳转到   
      <authentication   mode="Forms">   
      <forms   name="checkQX"   loginUrl="admin/login.aspx"   protection   ="All"   timeout="20"></forms>   
      </authentication>       
      <location   path="admin">   
      <system.web>   
      <authorization>   
      <deny   users="?"/>   
      </authorization>   
      </system.web> 
      </location>   
      这样用户没有登陆或Session过其的,去访问admin目录下的页面的时候,都会跳转到登陆页面.
      

  7.   

    首先你可以考虑使用<authentication   mode="Forms">来配置,基于页面的验证。这个可以自动跳转。   
      如果必须使用session那么可以考虑使用下面大额方法:   
      首先需要对所有的session访问做一个包装类,不能直接访问。你可以实现一个叫SessionManager的类里面有类似下面的方法:   
      public   object   CurrentSession(){   
      try{   
      if(HttpContext.Current.Session   !=   null){   
      return   HttpContext.Current.Session   
      }   
      else{   
      HttpContext.Current.Response.Redirect("login.aspx");   
      }   
      return   null;   
      }   
      catch(System.Threading.ThreadAbortException)   {   
      //   do   nothing   
      }   
      }   
      所有的session都从这个函数中获得。   
      Session_End是一个服务器方法,它是在Session过期后激发但是并不能在这里重定向页面。