现在的位置: 首页 > 综合 > 正文

页面是否登陆问题

2012年09月26日 ⁄ 综合 ⁄ 共 985字 ⁄ 字号 评论关闭
  第一种  在js里边写代码  
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(
typeof(QLflow));
if (!IsPostBack)
{
Page.RegisterStartupScript(
"","<script>LoginFun();</script>");

//接收上个页面传来的值
if (Request.QueryString["proid"] != null || Request.QueryString["proid"] != "")
{
tmpid.Value
= Request.QueryString["proid"];
iname.Value
= Request.QueryString["iname"];
}
}
}
//是否登录验证
function LoginFun()
{
     var cookie= document.cookie.split(',');
     if(cookie==null ||cookie=="" )
     {
        window.location.href="Login.aspx";
     }
}

  第二种:每个页面写上这个

protected void Page_Load(object sender, EventArgs e)
{
object obj = Request.Cookies["username"];
if (obj == null)
{
Response.Redirect(
"Login.aspx");
}
}

  第三种:单独一个aspx里边写上  第二种的简化版

http://support.microsoft.com/kb/224363/zh-cn

object obj = Request.Cookies["username"];
if (obj == null)
{
Response.Redirect(
"Login.aspx");
}

  然后每个页面引用 

protected void Page_Load(object sender, EventArgs e)
{
    Server.excute("sessinostate.aspx")
}

  当然还有更好的办法 

http://space.itpub.net/12639172/viewspace-673140  回头再研究  我这个项目适合第二种  很想用另外一种办法  可惜 不想改动


抱歉!评论已关闭.