צפיות
תשובות
איך בודקים אם משתמש מחובר
שלום,
זהו מסך הלוגין שלי:
protected void Page_Load(object sender, EventArgs e)
{
Session["admin"] = false;
if (IsPostBack)
{
return;
}
HttpCookie cUserName = Request.Cookies["UserName"];
HttpCookie cPass = Request.Cookies["UserPass"];
/*if (cUserName != null && cPass != null)
{
Login2(cUserName.Value, cPass.Value);
}*/
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Authenticated;
if (Authenticated == true && Login1.RememberMeSet == true)
{
HttpCookie cUserName = new HttpCookie("UserName");
cUserName.Value = Login1.UserName;
cUserName.Expires = DateTime.Now.AddYears(2);
Response.Cookies.Add(cUserName);
HttpCookie cPass = new HttpCookie("UserPass");
cPass.Value = Login1.Password;
cPass.Expires = DateTime.Now.AddYears(2);
Response.Cookies.Add(cPass);
}
if (Authenticated == true)
{
if (Request.QueryString["url"] != null && !Request.QueryString["url"].Equals(""))
Response.Redirect(Request.QueryString["url"]);
Response.Redirect("About/About.aspx");
}
}
private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
{
bool boolReturnValue = false;
string strConnection = @"Data Source=SARIT-DELL;Initial Catalog=PetsProj;Integrated Security=True";
SqlConnection Connection = new SqlConnection(strConnection);
String strSQL = "Select * From UserDetail";
SqlCommand command = new SqlCommand(strSQL, Connection);
SqlDataReader Dr;
Connection.Open();
Dr = command.ExecuteReader();
while (Dr.Read())
{
if ((UserName == Dr["UserName"].ToString()) & (Password == Dr["UserPass"].ToString()))
{
boolReturnValue = true;
Session["UserFirstName"] = Dr["UserFirstName"].ToString();
Session["UserLastName"] = Dr["UserLastName"].ToString();
Session["User"] = Dr["UserName"];
}
}
Dr.Close();
return boolReturnValue;
יש לי דף של עגלת קניות ואני רוצה ברגע שמשתמש לוחץ על כפתור לבדוק אם הוא מחובר או לא.
בדקתי את כל האפשרויות של isauthenticate וכו' אבל זה לא עובד, זה כביכול לא מזהה שהמשתמש מחובר.
האם יכול להיות שלא נשמר לי הSESSION פתוח?
אודה מאוד על עזרתכם!
2 תשובות
לא חשוב, נפתרה הבעיה
תודה בכל מקרה
כדאי שתכתוב את הפתרון