Dan*_*don 1 asp.net security authentication impersonation
这是一个简单的问题,我已经坚持了一段时间.
当我< identity impersonate=true >在我的web.config中设置以便asp.net自动模拟登录用户(或者如果不使用Windows身份验证则匿名帐户),asp.net模仿的身份来自哪里?
本文档:http://msdn.microsoft.com/en-us/library/ff649264.aspx显示了三个可以检索有关已登录用户的信息的位置:
Httpcontext.Current.userSystem.Threading.Thread.CurrentSystem.Security.Principal.WindowsIdentity.GetCurrent当我< identity impersonate=true >在web.config中设置时,似乎这些位置中没有一个始终匹配模拟的身份.
我想知道模仿身份来自哪里.
具体来说,我的意思是在较低的级别询问,在运行时从哪里获取身份.我熟悉IIS的配置,但我想知道如何在运行时检索身份以及它来自何处.为了便于讨论,我们假设身份是在IIS中设置的,而不是在web.config文件中设置的.
启用模拟后,身份将来自IIS.会发生什么是ASP.NET模拟IIS提供的访问令牌.
用于运行进程以启动的原始访问令牌仍然可用.这可能是使用问题中提到的三个API的混乱的根源.
Thread.CurrentPrincipal&HttpContext.Current.User:该行另一端的用户身份.
WindowsIdentity.GetCurrent:正在执行的实际基础Windows帐户.
HttpContext.Current.User中重复的原因是ASP.NET开发人员的便利.
编辑:
当IIS配置为在集成Windows身份验证下运行,并且 ASP.NET启用了模拟时,以下代码将使我们能够将代码作为基础帐户运行.
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool RevertToSelf();
protected void Page_Load(object sender, EventArgs e)
{
var me = WindowsIdentity.GetCurrent();
// At this point:
// me.Name = Domain\UserName
// me.AuthenticationType = Kerberos
if (RevertToSelf())
{
var underMe = WindowsIdentity.GetCurrent();
// At this point:
// underMe.Name = IIS APPPOOL\DefaultAppPool
// underMe.AuthenticationType = Negotiate
}
}
Run Code Online (Sandbox Code Playgroud)
根据您要执行的操作,此页面有更多方法可以解决此问题:http://support.microsoft.com/kb/306158
| 归档时间: |
|
| 查看次数: |
3798 次 |
| 最近记录: |