频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

ASP.NET 2.0 中的 Windows 身份验证

来源: 作者: 出处:巧巧读书 2006-08-09 进入讨论组
上一页 1 2 3 4 5 下一页 

 

六、安全上下文

    。net Framework 使用以下两个接口封装 Windows 令牌和登录会话:

    · System.Security.Principal.IPrincipal

    · System.Security.Principal.IIdentity(它公开为 iprincipal 接口中的一个属性。)

    httpcontext.user

    在 ASP.NET 中,用 windowsprincipal 和 windowsidentity 类表示使用 Windows 身份验证进行身份验证的用户的安全上下文。使用 Windows 身份验证的 ASP.NET 应用程序可以通过 httpcontext.user 属性访问 windowsprincipal 类。

    要检索启动当前请求的 Windows 经过身份验证的用户的安全上下文,使用以下代码:

using System.Security.Principal;
...
// Obtain the authenticated user's Identity
WindowsPrincipal winPrincipal = (WindowsPrincipal)HttpContext.Current.User;

    windowsidentity.getcurrent

    WindowsIdentity.GetCurrent 方法可用于获得当前运行的 Win32 线程的安全上下文的标识。如果不使用模拟,线程继承 IIS 6.0(默认情况下的 NetworkService 帐户)上进程的安全上下文。

    该安全上下文在访问本地资源时使用。通过使用经过身份验证的初始用户的安全上下文或使用固定标识,您可以使用模拟重写该安全上下文。

    要检索运行应用程序的安全上下文,使用以下代码:

using System.Security.Principal;
...
// Obtain the authenticated user's identity.
WindowsIdentity winId = WindowsIdentity.GetCurrent();
WindowsPrincipal winPrincipal = new WindowsPrincipal(winId);

    thread.currentprincipal

    asp.net 应用程序中的每个线程公开一个 currentprincipal 对象,该对象保存经过身份验证的初始用户的安全上下文。该安全上下文可用于基于角色的授权。

    要检索线程的当前原则,使用以下代码:

using System.Security.Principal;
...
// Obtain the authenticated user's identity
WindowsPrincipal winPrincipal = (WindowsPrincipal) Thread.CurrentPrincipal();

    表 1 显示从各种标识属性获得的结果标识,当您的应用程序使用 Windows 身份验证且 IIS 配置为使用集成 Windows 身份验证时,可以从 ASP.NET 应用程序使用这些标识属性。

表 1:线程公开的 CurrentPrincipal Object
Web.config 设置 变量位置 结果标识

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

HttpContext
WindowsIdentity
线程

Domain\UserName
Domain\UserName
Domain\UserName

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

HttpContext
WindowsIdentity
线程

Domain\UserName
NT AUTHORITY\NETWORK SERVICE
Domain\UserName

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

HttpContext
WindowsIdentity
线程

用户提供的名称
Domain\UserName
用户提供的名称

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

HttpContext
WindowsIdentity
线程

用户提供的名称
NT AUTHORITY\NETWORK SERVICE
用户提供的名称

文章地址: http://www.qqread.com/aspdotnet/n196681.html 更多文章 更多内容请看Windows操作系统安装Windows权限设置Windows操作系统安全集专题,或进入讨论组讨论。
上一页 1 2 3 4 5 下一页 
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章