不能得到loginview值 [英] cant get value from loginview
问题描述
我想从一个LoginView用户名值。我试图从这里许多方法和其他网站。一些不工作,其他的只给我在电脑上或从AD登录。
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?
我想这code:
LoginName loginName = HeadLoginView.FindControl("HeadLoginName") as LoginName;
Label1.Text = (loginName.ToString());
所以也试过这code位置:
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());
但总是同样的错误,nullexeption和System.Web.UI.WebControls.LoginName坳TIPOSystem.Web.UI.WebControls.Login
but always same error, nullexeption and 'System.Web.UI.WebControls.LoginName' ao tipo 'System.Web.UI.WebControls.Login
但没有sucess
推荐答案
在这里,你有两种可能的方法:
Here you have two possible methods:
1),尝试从LoginView获得的LoginName,像这样的:
1) Try to get the LoginName from LoginView, like this:
LoginName loginName = (LoginName)HeadLoginView.FindControl("HeadLoginName");
2),或者你可以浏览到这个属性:
2) Or you can browse to this property:
HttpContext.Current.User.Identity.Name
欢呼声
这篇关于不能得到loginview值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!