用户和身份对象

用户对象实现 IPrincipal 接口,并且表示用户的安全性上下文,代码基于此用户运行。用户对象包括用户的身份(作为包含的 IIdentity 对象)以及用户所属的任何角色。

ASP.NET 提供了以下用户和身份对象实现:

WindowsPrincipalWindowsIdentity 对象代表用 Windows 身份验证进行验证的用户。利用这些对象,角色列表自动从 Windows 组集中获取,Windows 用户属于该组。
GenericPrincipalGenericIdentity 对象代表用 Forms 身份验证或其他自定义身份验证机制进行验证的用户。利用这些对象,角色列表通常从数据库中以自定义方式获取。
FormsIdentityPassportIdentity 对象代表分别用 Forms 和 Passport 身份验证机制进行验证的用户。

下面的表格说明了对于一系列的身份验证设置,从每个变量获得的结果身份保持一个 IPrincipal 和/或 IIdentity 对象。在表格中使用了一下缩写:

HttpContext = HttpContext.Current.User,其中 返回一个 IPrincipal 对象,它包含当前 Web 请求的安全性信息。这是经身份验证的 Web 客户端。
WindowsIdentity = WindowsIdentity.GetCurrent(),返回当前执行 Win32 线程的安全性上下文。
Thread = Thread.CurrentPrincipal,返回当前执行 .NET 线程的用户,该线程在 Win32 线程上运行。

 

IIS 匿名身份验证

Web.config 设置变量位置结果身份
<identity impersonate="true"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
线程

-
MACHINE/IUSR_MACHINE
-

<identity impersonate="false"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
线程

-
MACHINE/ASPNET
-

<identity impersonate="true"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
线程

Name provided by user
MACHINE/IUSR_MACHINE
用户提供名称

<identity impersonate="false"/><authentication mode="Forms" />

HttpContext
WindowsIdentity线程

Name provided by user
MACHINE/ASPNET
用户提供名称

 

IIS 基本身份验证

Web.config 设置变量位置结果身份
<identity impersonate="true"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
线程

域/用户名
域/用户名
域/用户名

<identity impersonate="false"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
线程

域/用户名
MACHINE/ASPNET
域/用户名

<identity impersonate="true"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
线程

用户提供名称
域/用户名
用户提供名称

<identity impersonate="false"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
线程

用户提供名称
MACHINE/ASPNET
用户提供名称

IIS 简要身份验证

Web.config:变量位置结果身份
<identity impersonate="true"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
线程

域/用户名
域/用户名
域/用户名

<identity impersonate="false"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
线程

域/用户名
MACHINE/ASPNET
域/用户名

<identity impersonate="true"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
线程

用户提供名称
域/用户名
用户提供名称

<identity impersonate="false"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
线程

用户提供名称
MACHINE/ASPNET
用户提供名称

IIS 集成 Windows

Web.config 设置变量位置结果身份
<identity impersonate="true"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
线程

域/用户名
域/用户名
域/用户名

<identity impersonate="false"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
线程

域/用户名
MACHINE/ASPNET
域/用户名

<identity impersonate="true"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
线程

用户提供名称
域/用户名
用户提供名称

<identity impersonate="false"/><authentication mode="Forms" />

HttpContext.WindowsIdentity
线程

用户提供名称
MACHINE/ASPNET
用户提供名称

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值