一个asp.net的小网站,有几个页面需要登录后才可以看的我就在登陆页面放了个:
  Session["UintName"] = txtUserName.Text;
  Response.Redirect("../News.aspx",true);然后在News.aspx里面放了个:
Server.Execute("sn/incs/checkPurview.aspx");  // 此处用户权限验证在checkPurview.aspx里面用了:
if (Session["UintName"] == null)
        {
            Response.Write("对不起,您没有权限!");
            Response.End();
        }
现在有个问题, 我登陆转向News.aspx是正常打开了但是一刷新News.aspx就打不开了,变成:“对不起,您没有权限!”
而且其它使用Server.Execute("sn/incs/checkPurview.aspx")也是没有通过验证。这个是什么情况?

解决方案 »

  1.   

     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
            {
                if (TextBox1.Text.Equals(""))
                {
                    Response.Write("<script>alert('用户名不能为空');</script>");
                }
                else if (TextBox2.Equals(""))
                {
                    Response.Write("<script>alert('密码不能为空');</script>");
                }
                else
                {
                    string name = TextBox1.Text.Trim().ToString();
                    string pass = TextBox2.Text.Trim().ToString();                string strWhere = " adminname='" + name + "' and adminpass='" + pass + "' ";
                    DataSet ds = new DataSet();
                    ds = bll.GetList(strWhere);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        Response.Write("<script>alert('登陆成功');location.href='index.aspx';</script>");
                        Session["admin"] = name;
                    }
                    else
                    {
                        Response.Write("<script>alert('登陆失败,请重新输入');</script>");
                    }
                }
            }
    if (!IsPostBack)
                {
                    if (Session["admin"] == null)
                    {
                       // Response.Write("<script>alert('登陆超时');top.location.href='login.aspx';</script>");
                       Response.Write("<script>alert('登陆超时');window.parent.location.href='login.aspx';</script>");                }
                    else
                    {
                      
                    }
                }
      

  2.   

    不要用Server.Execute,直接在News.aspx里面判断就行了
      

  3.   

    没用过Server.Execute 顶一下
      

  4.   

    直接用session判断,不用用execute跳转啦,或者让登录后的页面继承一下判断的页面,估计也可行
      

  5.   

    你为什么要用 Server.Execute
    你用Inlcude 或者做个用户自定义控件也可以啊。
    貌似 Server.Execute,是服务器端执行,运行后,其将创建一个新的会话。
      

  6.   

    把你page_load里面的代码用
    if (!IsPostBack)
                {
                   //你所有的验证代码
                }
    这样写的话刷新页面不会重复执行page_load里面的代码
      

  7.   

    使用Cookie,具体用法可以到百度中搜索。这个问题我也才解决。如果需要具体代码可以联系:[email protected]
      

  8.   

    登陆页面用:  Session["IsAdmin"] = (bool)dr["IsAdmin"];
    跳转后的页面用:
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    if (Session["IsAdmin"] != null)
                    {
                        if ((bool)Session["IsAdmin"])
                        {
                            HyperLink6.Visible = true;
                            HyperLink7.Visible = true;
                        }
                        else
                        {
                            HyperLink6.Visible = false;
                            HyperLink7.Visible = false;
                        }
                    }
                }你根据具体情况改改吧
      

  9.   

    很不好意思,找到原因了有个函数里面有个session.Clear()
      

  10.   

    晕...
    其实没必要这样判断.只需要再读一次
    if(session[""]!=null)
    {
    //已登录了.有session,自己的代码
    }
    else
    {
    //未登录...
    }