0

一旦用户通过身份验证和授权,应用程序就可以通过使用 User 对象的 Identity 属性来获取有关用户的信息。Identity 属性返回一个包含用户名和角色信息的对象。

下面是我用来理解这个概念的代码片段:-

private void Page_Load(object sender, System.EventArgs e)
{
 Label1.Text = User.Identity.IsAuthenticated.ToString();
 Label2.Text = User.Identity.Name;
 Label3.Text = User.Identity.AuthenticationType;
}

有没有其他方法可以获取用户身份?

4

2 回答 2

1

请澄清您是否想要以下内容..

如果您只想在调用 Page_Load 时从 ASP.NET WebPage 中获取用户身份,请创建一个 string[] 并执行以下操作

string strRawUser = Page.User.Identity.Name;

然后从那里 strRawUser 将有类似 "DomainName\UserName" 所以你需要将字符串拆分为 stringArray 并像这样获取字符串 [1] 值

string[] strRawUserSplitter = Page.User.Identity.Name.Split("\\");
Label2.Text = strRawUserSplitter[1]
于 2012-09-13T17:03:56.150 回答
0

您还可以使用 Principal Object 获取当前用户身份。

于 2012-09-13T16:51:50.317 回答