I am using Asp.Net
built-in membership framework
, I have a requirement where I need to display the name of the logged-in
user, my aspnet_users
table stores the user name something like this abc001
which is actually the usercode of the user , its user name is stored in another table which is linked to the aspnet_users
table with a foreign key constraint
.So how do I display the name of the user from that table in my navigation menu which will be floating towards the right.Much like Facebook
does , it displays logged-in
users name in the header.
Edit:
protected void cmdLogin_Click(object sender, EventArgs e)
{
if (Membership.ValidateUser(txtUsername.Text, txtPassword.Text))
{
HttpCookie authCookie = FormsAuthentication.GetAuthCookie(txtUsername.Text, false);
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, "");
authCookie.Value = FormsAuthentication.Encrypt(newTicket);
Response.Cookies.Add(authCookie);
GetUserName();
string redirUrl = FormsAuthentication.GetRedirectUrl(txtUsername.Text, false);
Response.Redirect(redirUrl);
}
}
public void GetUserName()
{
DataClasses1DataContext dt = new DataClasses1DataContext();
var name =( from nm in dt.Users_AdditionalInfos
where nm.UserCode== txtUsername.Text.Trim()
select nm).Single();
Global.UserName=name.FirstName +" "+ name.LastName;
}
Thanks