how to retrive username and other information after succefully login using loginid and passs

like

in login screen (user will use his/her)

Userid:xyz
Password:xxx

in home page

i want to dispaly his/her name !!!!

urgent help!!!!!!!!!!!!

Recommended Answers

All 16 Replies

maybe this is what you are looking for

Request.ServerVariables["LOGON_USER"].ToString()

you can use the "User" property of page.
for example, "string strUserId = User.Identity;
UserLabel.Text = strUserId;"
If you don't understand well, you can ask me in detail using MSN
Good luck~

blackdragon i rather he explain over here so we can all see the solution.

first, user login in.
Next, user id is stored in the property of page called "User"(Page.User)
You can get user id using this scritp;
string userId = User.Identity;
you can display this userId~~
That's enough?

i want to display user name which is in database table noy the id which is used to login..................

Why are you not using Session variable ? At the time of UserLogin, when User credential match/success, Just store the User Related information in Session variable and use this session variable in any page within your application.

Session["UserName"] = "Test";
Label1.Text = Session["UserName"].ToString();

Try by this !!

i want to display user name which is in database table noy the id which is used to login..................

ya i know tht but i want to display something like this

in my database table i have three columns

Userid: stu1
Password: stu1
StudentName: XYZ

i want to display username in welcome screen not the id which i use to login

So what the problem is ?
Yet you can show the StudentName as UserName in Welcome screen with the help of Session. You can do it like below code..

SqlDataAdapter objAdpt = new SqlDataAdapter("Select * from yourtable Where UserID='User Entered' And Password ='User Entered'", your connection);
DataTable objDt = new DataTable ();
objAdpt.Fill(objDt);
if(objDt.Rows.Count > 0)
{
    Session["UserName"] = objDt[0]["StudentName"].ToString();
}

Now on Welcome screen Lable, just retrieve value from Session like below :
Label1.Text = Session["UserName"].ToString();

that's all...
try by this and let us know If you stil have any confusion..

ya i know tht but i want to display something like this

in my database table i have three columns

Userid: stu1
Password: stu1
StudentName: XYZ

i want to display username in welcome screen not the id which i use to login

In the login page in case of successful login write the following code
Session["userid"] = t1.Text;
Now you have session variable in all your website pages called userid
In the second page write code like this
String userid = Session["userid"].ToString();
sqlDataAdapter d=new sqlDataAdapter("select studentname from students where userid="+userid,connstring);
Label1.text=....... studentname which retrieve from the previous statement

thanks

mohammed yaghi - UserID and UserName is different. Why are you storing UserID in Session and then again storing value of session in String variable and executing the query to retrieve only UserName in case of Successful login.
try to minimize the code always. The reason is in large application this type of things makes delay to run application..

In the login page in case of successful login write the following code
Session["userid"] = t1.Text;
Now you have session variable in all your website pages called userid
In the second page write code like this
String userid = Session["userid"].ToString();
sqlDataAdapter d=new sqlDataAdapter("select studentname from students where userid="+userid,connstring);
Label1.text=....... studentname which retrieve from the previous statement

thanks

rohand The solution required to login by userid and then retrieve name from query
Dear I assigned session to string just for explaining and details explian just
I Know that I can do it without storing in variable
thanks for advice

hi rohand its showing errorr

cannot apply indexing with [] to an expression of type 'System.Date.DataTable'

why session..

use shortcut..

after successful credential match

{
 FormsAuthentication.SetAuthCookie(txtUserName.Text,false);
 Response.Redirect("NextPage.aspx");
}

on NextPage.aspx add a Label

on FormLoad Event
{
if(Request.IsAuthenticated)
 Label1.Text = User.Identity.Name;
else
 // Redirect to Login Page
}

// Done and Hope that helps

thanks for help ... but i used another method to get user name...
thanks to u all!!!!

step 1:

create a session of your text storing like this. this line is appear at your ok(login) button last line.

session["your name"]=username.text

step 2:

create a lable box at any one of the corner of your form without text property.

then write the code for in your form load action

label1.text=session["yourname"].text


Try this and send the result to my mail

My mail id samkaraja@gmail.com

With regards

Rajapandian

ok that is one type to view

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.