Hi im new to asp.net. . . im doing my final year project.How to use session variables in application using VC# and I also need to check with data base?
A:
A session variable you can treat like an array of key value pairs. For example
Session["key"] = "Hello World";
string tmp = (String)Session["key"];
That is it. Pretty simple.
Edit: From feedback
public class User
{
public string firstname;
public string lastname;
}
if (DoesUserExist(username, password)
{
User newUser = new User();
newUser.firstname = "Joe";
newUser.lastname = "Soap";
Session["LoggedInUser"] = newUser;
}
Then on other pages
User currentUser = Session["LoggedInUser"];
if (currentUser == null)
{
Response.Redirect("login.aspx");
}
This code is no where near perfect but you get the idea.
uriDium
2010-02-24 07:39:16
i just need to store the informatiom of the current user and to check whether the user already exist in database or not –
shalu
2010-02-24 08:19:28
A:
I might be a little confused, but why do you want to use Session in a Windows Forms application? If it's for credentials, you can store credentials in an class exposed to your entire application. That is, if you are referring to "Windows Forms" and not "Web Forms".
PieterG
2010-02-24 07:41:27
i just need to store the informatiom of the current user and to check whether the user already exist in database or not
shalu
2010-02-24 08:11:51