I am trying to get the username value from the loginView. I tried many methods from here and other sites. Some don't work and others only give me the login on the computer or from the AD.
Does anybody know, how to take the username of the logged person on the site?
i tried this code:
LoginName loginName = HeadLoginView.FindControl("HeadLoginName") as LoginName;
Label1.Text = (loginName.ToString());
so also tried this code here:
//var Login1 = ((Login)HeadLoginView.FindControl("HeadLoginName"));
//var Login1 = ((LoginName)HeadLoginView.FindControl("HeadLoginName"));
//LoginName Login1 = ((LoginName)HeadLoginView.FindControl("HeadLoginName"));
//string userName = Login1.UniqueID.ToString();
//string Username = User.Identity.Name;
//Label1.Text = Username;
//LoginName Login1 = ((LoginName)HeadLoginView.FindControl("HeadLoginName"));
//string userName = Convert.ToString(Login1);
//Login Login1 = ((Login)HeadLoginView.FindControl("HeadLoginName"));
//string userName = Login1.UserName.ToString();
//var userName = ((Login)HeadLoginView.FindControl("HeadLoginName"));
//Label1.Text = Convert.ToString(userName);
//LoginName loginName = (LoginName)HeadLoginView.FindControl("HeadLoginName");
//Label1.Text = Convert.ToString(loginName);
//string merda = (HttpContext.Current.User.Identity.Name);
//LoginName loginName = HeadLoginView.FindControl("HeadLoginName") as LoginName;
//Label1.Text = (loginName.ToString());
but always same error, nullexeption and 'System.Web.UI.WebControls.LoginName' ao tipo 'System.Web.UI.WebControls.Login
but no sucess
Here you have two possible methods:
1) Try to get the LoginName from LoginView, like this:
LoginName loginName = (LoginName)HeadLoginView.FindControl("HeadLoginName");
2) Or you can browse to this property:
HttpContext.Current.User.Identity.Name
cheers
use:
Login login2 = (Login)(LoginView1.FindControl("Login2"));
if(login2!=null) {
string user=login2.UserName;
string pass=login2.Password;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.