單點登陸後的退出問題
我用了孟子的單點登陸,代碼如下: private void Button1_Click(object sender, System.EventArgs e)
{
string sName=TextBox1.Text;
SqlDataReader dr;
string findSQL = "SELECT COUNT(USER_NAME) FROM User_Name WHERE NAME = ' "+TextBox1.Text+ " ' AND PASSWORD= ' "+TextBox2.Text+ " ' ";
string getSQL = "SELECT * FROM User_Name WHERE NAME = ' "+TextBox1.Text+ " ' AND PASSWORD= ' "+TextBox2.Text.Trim()+ " ' ";
SqlConnection conn = new SqlConnection( "Data Source=(local);User ID=admin;Password=123;database=TEST ");
SqlCommand findCmd = new SqlCommand(findSQL,conn);
SqlCommand getCmd = new SqlCommand(getSQL, conn);
try
{
conn.Open();
dr=getCmd.ExecuteReader();
if(dr.Read())
{
string lob = dr[ "Type "].ToString();
if (lob == "MB PE ")
{
string sKey = TextBox1.Text + "_ " + TextBox2.Text;
string sUser = Convert.ToString(Cache[sKey]);
if (sUser == null ¦ ¦ sUser == String.Empty)
{
TimeSpan SessTimeOut = new TimeSpan(0,0,System.Web.HttpContext.Current.Session.Timeout,0,0);
HttpContext.Current.Cache.Insert(sKey,sKey,null,DateTime.MaxValue,SessTimeOut,
System.Web.Caching.CacheItemPriority.NotRemovable,null);
Session[ "Users "] = sKey;
Session[ "MBLoginID "]=dr[ "Name "].ToString();
Session[ "MBusername "]=dr[ "China_Name "].ToString();
Response.Redirect( "file.aspx ");
}
else
{
Response.Write( " <script > alert( '你的帳號已經登陸! '); </script > ");
return;
}
}
}
else
Label1.Text= "用戶名或密碼錯誤 ";
}
catch(Exception ee)
{
Label1.Text=ee.Message;
}
finally
{
conn.Close();
}
}
}
else
Label1.Text= "用戶名或密碼錯誤 ";
}
catch(Exception ee)
{
Label1.Text=ee.Message;
}
finally
{
conn.Close();
}
}
退出代碼如下:
private void Page_Load(object sender, System.EventArgs e)
{
// 在這裡放置使用者程式碼以初始化網頁
if (!IsPostBack)
{
this.Page.Response.Redirect( "log.aspx ");
Session.Remove( "Users ");
Session.Remove( "MBLoginID ");
Session.Remove( "MBusername ");
Cache.Remove( "sKey ");
Cache.Remove( "Users ");
Session.Clear();
Session.Abandon();
}
但是運行退出後再登陸時,卻說我仍然已經登陸了呢?
為什麼
但是運行退出後再登陸時,卻說我仍然已經登陸了呢?
為什麼