我正在尝试从 loginView 获取用户名值。我从这里和其他网站尝试了很多方法。有些不起作用,有些只给我在计算机上或从 AD 登录。
有谁知道,如何在网站上获取登录人的用户名?
我试过这段代码:
LoginName loginName = HeadLoginView.FindControl("HeadLoginName") as LoginName;
Label1.Text = (loginName.ToString());
所以也在这里尝试了这段代码:
//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());
但总是相同的错误,nullexeption 和 'System.Web.UI.WebControls.LoginName' ao Tipo 'System.Web.UI.WebControls.Login
但没有成功