我使用的是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;
}
谢谢