how we create session in login page in asp .net with c# give me full example......
The Session object stores information about, or change settings for a user session. Variables stored in a Session object hold information about one single user, and are available to all pages in one application. Common information stored in session variables are name, id, and preferences.
Session is a feature in ASP.NET Core that enables us to save/store the user data. Session stores the data in the dictionary on the Server and SessionId is used as a key. The SessionId is stored on the client at cookie. The SessionId cookie is sent with every request.
Assuming that your code is in the page (either inline or in the code behind) you can just use...
DataType someValue = (DataType)Session["SessionVariableNameHere"]; //Getter
Session["SessionVariableNameHere"] = someNewValue; //Setter
Obviously you'll need to name your session variable properly, and cast to the appropriate data type when you get it back out of the session.
EDIT - A Full Example
protected void Login1_LoggedIn(object sender, EventArgs e)
{
Session["LoginTime"] = DateTime.Now;
}
and later in a page load...
protected void Page_Load(object sender, EventArgs e)
{
Literal1.Text = "Last Online: " + ((DateTime)Session["LoginTime"]).ToString("yyyy-MM-dd");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With