您好,所以我想检查数据库是否用户已经登录,然后如果他在这里登录停止登录是我的代码示例,请提供帮助。
protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
String name = ((Login)LoginView1.FindControl("Login1")).UserName;
SqlConnection source_db = new SqlConnection();
source_db.ConnectionString = ConfigurationManager.ConnectionStrings["source"].ConnectionString;//konfiguracja polaczenia z web.cfg
SqlCommand sql_polecenie3 = new SqlCommand("select Status from aspnet_Users where UserName='" + name + "';", source_db);
try
{
source_db.Open();//otwiera polaczenie
if ((int)sql_polecenie3.ExecuteScalar() == 1)
{
Label1.Visible = true;
}
else
{
Label1.Visible = false;
}
source_db.Close();//zamyka polaczenie
}
catch (Exception)
{
source_db.Close();//zamyka polaczenie
}
}