顯示當前用戶的名稱,我使用Asp.Net
內置membership framework
,我有我需要顯示logged-in
用戶的名字,我的aspnet_users
表存儲的用戶名像這樣abc001
這是一個要求實際上是用戶的用戶代碼,其用戶名存儲在另一個表中,該表與aspnet_users
錶鏈接,其中foreign key constraint
。因此,如何在我的導航菜單中從該表中顯示用戶的名稱,該名稱將向右。就像Facebook
一樣,它在標頭中顯示logged-in
用戶名。 編輯:在橫向菜單
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;
}
感謝
但名稱實際上存儲在鏈接到內置表的不同表中,所以我認爲Membership.GetUser()。UserName不會給我名稱。 –