当前位置:编程学习 > C#/ASP.NET >>

怎么才能经过登陆才跳转到相应的页面

别人知道我页面的路径  怎么样才能让别人先登录才能进入相应的页面 --------------------编程问答-------------------- 加过滤 --------------------编程问答-------------------- 用判断的方法,如下代码:

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                    username = Request["un"].ToString();
                    sid = EnDecrypt.DecryptText(Request["sid"].ToString());
                    if (Session["CheckUserCode"] == null || Session["CheckUserCode"].ToString() == "")
                    {
                        Response.Write("<script>alert('你还没有登录,请重新登录!' )</script>");
                        Response.Write("<script>top.location.href='" + myroot + "/Login.aspx';</script>");
                        Response.End();
                    }
                    strdate = System.DateTime.Now.ToString("yyyy-MM-dd");
                    this.iddate.Value = System.DateTime.Now.ToString("yyyy-MM-dd");
                }
                catch
                {
                    Response.Write("<script>alert('你还没有登录,请重新登录!' )</script>");
                    Response.Write("<script>top.location.href='" + myroot + "/Login.aspx';</script>");
                    Response.End();
                }
            }
        }
--------------------编程问答-------------------- 用session判断用户是否存在 --------------------编程问答-------------------- 可以写个类,判断也是当前页面url,如果只是login。aspx页面不用跳转
否则全部跳到制定的页面去。 --------------------编程问答-------------------- 用户权限限制。session限制,还有就是要进行安全设置。。。 --------------------编程问答-------------------- 用Session保存登录用户,访问页面的时候判断Session中用户是否为空,为空则提示先登录 --------------------编程问答--------------------
引用 2 楼 lfywy 的回复:
用判断的方法,如下代码:
C# codeprotectedvoid Page_Load(object sender, EventArgs e)
        {if (!IsPostBack)
            {try
                {
                    Response.ContentEncoding= System.Text.Encoding.GetEncoding("GB2312");
                    username= Request["un"].ToString();
                    sid= EnDecrypt.DecryptText(Request["sid"].ToString());if (Session["CheckUserCode"]==null|| Session["CheckUserCode"].ToString()=="")
                    {
                        Response.Write("<script>alert('你还没有登录,请重新登录!' )</script>");
                        Response.Write("<script>top.location.href='"+ myroot+"/Login.aspx';</script>");
                        Response.End();
                    }
                    strdate= System.DateTime.Now.ToString("yyyy-MM-dd");this.iddate.Value= System.DateTime.Now.ToString("yyyy-MM-dd");
                }catch
                {
                    Response.Write("<script>alert('你还没有登录,请重新登录!' )</script>");
                    Response.Write("<script>top.location.href='"+ myroot+"/Login.aspx';</script>");
                    Response.End();
                }
            }
        }

这个可以 --------------------编程问答--------------------
引用 6 楼 d_star 的回复:
用Session保存登录用户,访问页面的时候判断Session中用户是否为空,为空则提示先登录


登陆的时候 给session赋值。
然后再页面上再判断 session是否 为空
如果为空就叫他 登陆就好了。 --------------------编程问答-------------------- 用Session保存一下用户的登陆状态!需要登陆才能查看的网页加一个检查。 --------------------编程问答--------------------  protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminName" ]== null)
        {
            Response.Write("<script language='javascript'>alert('请登录后再进入!');window.location.href('Login.aspx');</script>");
        }
    }
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,