मेरी टिप्पणी के बारे में अधिक जानकारी देने के लिए:
चरण 1
एक Sessions
बनाएं तालिका जिसमें निम्नलिखित फ़ील्ड शामिल हैं:
SessionId ( Primary Key ) char(24)
UserId ( Foreign Key to Users table ) int
LoginDate datetime
चरण 2
अपना Sessions
बनाएं कक्षा।
public class Session {
public string Sessionid { get; set; }
public int UserId { get; set; }
public DateTime LoginDate { get; set; }
}
चरण 3
यदि आपके पास DoLogin
. नामक फ़ंक्शन है ।
public void DoLogin() {
//validation commes here...
//create your session
Session["User"] = user; //user is your User class object
//create session class for db
Session session = new Session();
session.SessionId = ""; //you can generate here a 24 character string
session.UserId = user.Id;
session.LoginDate = DateTime.Now;
db.Add(session); //add session to db
}
चरण 4
यह जांचने के लिए एक फ़ंक्शन बनाएं कि उपयोगकर्ता पहले से लॉग इन है या नहीं।
public bool IsLoggedIn(User user) {
Session session = db.GetSession(user.Id); //Get session of the user
if(session != null)
{
return true;
} else {
return false;
}
}