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>");
}
}










