你如何获得用户身份? [英] How do you get a User Identity?

查看:129
本文介绍了你如何获得用户身份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Once a user is authenticated and authorized, the application can get information about the user by using the User object’s Identity property. The Identity property returns an object that includes the user name and role information.

下面是我用理解的概念的code片断: -

Below is the code snippet which I have used to understand the concept:-

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;
}

是否有任何其他方式来获取用户身份?

Is there any other way to get the User Identity?

推荐答案

请澄清,如果你想要像下面的下面。

Please clarify if you are wanting something like the following below..

如果你只是希望用户身份..从ASP.NET网页时在Page_Load被称为创建一个字符串[]和做类似以下

If you just want the users Identity.. from an ASP.NET WebPage when the Page_Load is called create a string[] and do something like the following

string strRawUser = Page.User.Identity.Name;

然后再从那里strRawUser都会有类似域名\\用户名
所以,你需要将字符串分割成一个字符串数组并获得字符串[1]值这样的

Then from there strRawUser will have something like "DomainName\UserName" So you need to Split the string into an stringArray and get the string[1] value like this

string[] strRawUserSplitter = Page.User.Identity.Name.Split("\\");
Label2.Text = strRawUserSplitter[1]

这篇关于你如何获得用户身份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆