文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>SSO单点登录

SSO单点登录

时间:2011-03-12  来源:奋斗张

 protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "" || TextBox2.Text == "")
        {

            Response.Write("<script> alert('用户名和密码不能为空!')</script>");
        }
        else
        {
            string connnn = ConfigurationManager.ConnectionStrings["MyOfficeConnectionString"].ConnectionString;

            connection = new SqlConnection(connnn);
            connection.Open();
            string sqlst = "select * from mymember where sname='" + TextBox1.Text + "' and spwd='" + TextBox2.Text + "'";
            SqlDataAdapter sa = new SqlDataAdapter(sqlst, connection);
            DataSet ds = new DataSet();
            sa.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string str_Key = TextBox1.Text + "_" + TextBox2.Text;
                string str_User = Convert.ToString(Cache[str_Key]);
                //得到Cache中的给定str_Key
                if (str_User == string.Empty)
                {
                    //Cache 中没有改str_Key 的项目表明用户没有登陆或者登陆超时
                    TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
                    HttpContext.Current.Cache.Insert(str_Key, str_Key, null, DateTime.MaxValue, SessTimeOut, CacheItemPriority.NotRemovable, null
                        );
                    Session["User"] = str_Key;
                    Session["username"] = "欢迎" + TextBox1.Text + "光临本网站";
                }
                else
                {
                    Session["username"] = "抱歉" + TextBox1.Text + "已经登陆";
                }
                Response.Redirect("index.aspx");
            }
            else
            {
                Response.Write("<script>alert('用户名和密码错误!')<script>");
            }
        }

相关阅读 更多 +
排行榜 更多 +
超级燃烧

超级燃烧

休闲益智 下载
梦境护卫队最新版

梦境护卫队最新版

策略塔防 下载
玉溪高古楼app最新版下载

玉溪高古楼app最新版下载

生活实用 下载