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

SESSION

我的后台管理系统:用的是母版页做框架和是否登陆验证,但是登陆成功之后,没操作几个页面就退出来了,要求要重新登陆:

验证代码如下:


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           
            try
            {
                UserInfo userinfo = new UserInfo();
                userinfo = (UserInfo)Session["UserInfo_log"];
              if (userinfo.Purview != 1)
                {
                    Response.Write(Common.OpenLogin("温馨提示:您的会话有误!不能操作系统!请重新登陆!", "Login.aspx"));
                    Response.End();
                }
              
            }
            catch
            {
                Response.Write("<script language=javascript>alert('温馨提示:您与系统会话不成功!请重新登陆!');window.parent.document.location='Login.aspx';</script>");
                Response.End();
            }

        }
    }
}



登陆验证和SESSION设置代码

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Do_Object_Login_Ajax : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string Action = Request.QueryString["Action"].ToString();
            Operate db1;
            switch (Action)
            {
                case "CheckUser":
                    string username = Request.QueryString["UserName"].ToString();
                    string password = Request.QueryString["Password"].ToString();
                    string yzm = Request.QueryString["YZM"].ToString();
                    yzm = yzm.ToLower();
                    db1 = new Operate();
                    UserInfo Userlist = db1.CheckLogin(username, password);
                    string txt = "";
                    if (yzm != Session["VNum"].ToString())
                    {
                        txt = "alert('温馨提示:验证码不正确!');";
                    }
                    else
                    {
                        if (Userlist.Purview == 0)
                        {
                            txt = "alert('温馨提示:用户名和密码不正确!');";

                        }
                        else
                        {
                            Session["UserInfo_log"] = Userlist;
                            Session["NowDateTime"] = DateTime.Now.ToString();
                            txt = "window.open('main.htm','_parent');";
                        }                       
                    }
                    Response.Write(txt);
                    break;







                case "Quit":
                    db1 = new Operate();
                    UserInfo SessionValue2 = new UserInfo();
                    SessionValue2 = (UserInfo)Session["UserInfo_log"];
                    string NowDateTime2 = Session["NowDateTime"].ToString();
                    string IP2 = Page.Request.UserHostAddress.ToString();
                    if (db1.Log_on(SessionValue2.UserName, IP2, NowDateTime2))
                    {

                        IDictionaryEnumerator em = HttpContext.Current.Cache.GetEnumerator();
                        while (em.MoveNext())
                        {
                            HttpContext.Current.Cache.Remove(em.Key.ToString());
                        }
                        Session.RemoveAll();

                        txt = "alert('温馨提示:退出系统操作成功!');window.location='Login.aspx';";
                    }
                    else
                    {
                        txt = "alert('温馨提示:操作发生非法错误!');window.close();";
                    }

                    Response.Write(txt);
                    break;
                default:
                    break;
            }
            Response.End();
        }
    }
}




麻烦高手们帮忙解决,我已经用了好多方法,  SESSION.TIMEOUT也设置了长时间,WEBCONFIG也设置了SESSION长时间,但是均不起用.  已经困扰我一个月了. --------------------编程问答-------------------- SESSION 不稳定,
很容易丢失, 建议你换一种方法 --------------------编程问答-------------------- 是很不稳定.经常有时登陆在线时间长一点,有时又慢一点!   大家通常用什么方法啊?
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,