tags:

views:

26

answers:

2

i am working on asp.net 2.0 and sql server 2005 i am using login authentication where userid = CJ and password = 123 when i click on login button the text welcome CJ must be displayed. on redirected page any help will be welcome

A: 

Store your user data in a session after the user was validated, and clean the session on logout. Storing you logged user in a session you can access you user from any page.

Andrei Bularca
can u show a example please
go to google, and type in "ASP.NET Forms Authentication".
RPM1984
A: 

If your user is valid store it in a session :

MyUser currentUser = UserLogin(userName, password);
if(currentUser!=null){
    Session["loggedUser"] = current;
    Response.Redirect("~/Default.aspx");
}
else
{
  //User authentication failed
}

When you access the logged user check if the session variable is null :

if(Session["loggedUser"]!=null)
{
   MyUser currentUser = (MyUser)Session["loggedUser"];
}

When you click the logout button clean your session variable (inside your Logout method) :

Session["loggedUser"] = null;

Good luck!

Andrei Bularca

related questions