在类文件里,Session失效时,怎样直接跳转到登录页面

dingjian2008 2009-11-06 12:29:18
我的一个类文件里有这样一个属性,如下:
/// <summary>
/// 用户基本信息
/// </summary>
public static UserInfo User_Info
{
get
{
if (HttpContext.Current.Session["UserInfo"] == null)
{
Page executingPage = HttpContext.Current.Handler as Page;
ScriptManager.RegisterClientScriptBlock(executingPage, executingPage.GetType(), "", "window.open('login.aspx','','')", true);
return null;
}
else
return (UserInfo)HttpContext.Current.Session["UserInfo"];
}
}
我希望当Session失效时,直接跳转到登录页面,可是执行后发现并没有成功跳转,还是返回的空,希望朋友们帮忙想想办法
...全文
147 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
mzjmicrosoft 2009-11-06
  • 打赏
  • 举报
回复
if (base.Session["UserId"] == null || base.Session["UserId"].ToString().Equals(""))
{
Response.Redirect("~/Error.aspx");
}
dingjian2008 2009-11-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wuyq11 的回复:]
通过BasrPage或IHtttpMoudle实现
public class BasePage : System.Web.UI.Page
    {
      public  BasePage()
      {

      }
     

      protected override void OnInit(EventArgs O)
      {
          if (base.Session["UserId"] == null || base.Session["UserId"].ToString().Equals(""))
          {
              Response.Redirect("~/Error.aspx");
          }
      }
    }
[/Quote]
这个是不行的,当页面不是刚加载进来的时候,这段代码不就没用了?这个类里的属性是可能在按钮事件里调用触发的。
另外,一楼的朋友,这段脚本确实是走了,但是没有跳转
行间 2009-11-06
  • 打赏
  • 举报
回复
同意二楼.
hecong875 2009-11-06
  • 打赏
  • 举报
回复
1楼正解!
wuyq11 2009-11-06
  • 打赏
  • 举报
回复
通过BasrPage或IHtttpMoudle实现
public class BasePage : System.Web.UI.Page
{
public BasePage()
{

}


protected override void OnInit(EventArgs O)
{
if (base.Session["UserId"] == null || base.Session["UserId"].ToString().Equals(""))
{
Response.Redirect("~/Error.aspx");
}
}
}
lirenniao 2009-11-06
  • 打赏
  • 举报
回复
没有执行吧?
iqlife 2009-11-06
  • 打赏
  • 举报
回复
Response.Redirect("~/你的页面");
flyerwing 2009-11-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wuyq11 的回复:]
通过BasrPage或IHtttpMoudle实现
public class BasePage : System.Web.UI.Page
    {
      public  BasePage()
      {

      }
     

      protected override void OnInit(EventArgs O)
      {
          if (base.Session["UserId"] == null || base.Session["UserId"].ToString().Equals(""))
          {
              Response.Redirect("~/Error.aspx");
          }
      }
    }
[/Quote]
类似这个吧

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧