小弟在global.asax文件中的Application_AcquireRequestState事件中写了如下的代码:protected void Application_AcquireRequestState(Object sender, EventArgs e)
{
if(Session["UserName"] == null || (string)Session["UserName"] =="")
Response.Redirect("default.aspx"); //未登陆返回首页
}结果连主页default.aspx都打不开了,也不报错,不知是为什么。请各位大哥指教下。
PS:这是小弟在csdn的处子贴,没有银子给大家。另外,如果在global.asax中写了事件代码,在cs文件中还要添加什么代码来引用这个事件?感恩涕零!

解决方案 »

  1.   

    你在不停的Response.Redirect("default.aspx");
      

  2.   

    Application_AcquireRequestState在你每次请求的时候都会执行。Response.Redirect("default.aspx")重新请求你的default.aspx,再次执行这个Application_AcquireRequestState事件。。如此反复
      

  3.   

    那如何解决这个问题呢?
    Response.Redirect("default.aspx",false)这样好像也解决不了呀?
      

  4.   

    我就是想判断用户是否登录  不知道在global.asax里面怎么写?
      

  5.   

    if(!HttpContext.Current.Request.Path==your virtual path of default.aspx)
    {
     if(Session["UserName"] == null || (string)Session["UserName"] =="") 
     Response.Redirect("default.aspx"); }
      

  6.   

    protected void Application_AcquireRequestState(Object sender, EventArgs e)
    {
    if(!(HttpContext.Current.Request.Path=="default.aspx"))
          {
     if(Session["UserName"] == null || (string)Session["UserName"] =="")
     Response.Redirect("default.aspx"); //未登陆返回首页
          }
    }
    我这样写还是打不开那个 default.aspx 这个页面?
      

  7.   

    判断用户是否登录,非要在global.asax里写吗?
    要是非要在global.asax里写,你可以这样写写看
        void Application_Start(object sender, EventArgs e) 
        {
            // 在应用程序启动时运行的代码
            Application.Lock();
            Application["UserName"] = null;
            Application.UnLock();
        }
        void Session_End(object sender, EventArgs e) 
        {
            // 在会话结束时运行的代码。 
            // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
            // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer 
            // 或 SQLServer,则不会引发该事件。
            Application.Lock();
            Application["UserName"] = null;
            Application.UnLock();    }
      

  8.   

    HttpContext.Current.Request.Path这个是相对路径
    你最好全部TOUPPER()后判断是不是等于/DEFAULT.ASPX
      

  9.   

    if(!(HttpContext.Current.Request.Path=="default.aspx")) 这句的default.aspx 也是个相对路径呀
    为什么进度条走到一半 不走了?
      

  10.   

    if(!(HttpContext.Current.Request.Path=="default.aspx")) 这句的default.aspx 也是个相对路径呀 
    为什么进度条走到一半 不走了?
      

  11.   

    HttpContext.Current.Request.Path取得的是一个虚拟路径,你可以输出这个路径看看写的对不对。
      

  12.   

    好了问题解决了,虽然没有分,但还是要结了。感谢viewstates和capucivar