在声明感知应用程序中保存原始WindowsIdentity

时间:2018-06-21 16:53:39

标签: c# asp.net-mvc impersonation claims-based-identity windows-identity

我有一个用MVC5开发的声明感知应用程序。我遇到的问题是当我需要对一个特定功能使用模拟时。我无法将声明标识转换为Windows标识。我也尝试过根据upn创建Windows身份,但是我得到的模拟级别无效。到目前为止,我要做的唯一一件事就是在索赔转换之前将原始WindowsPrincipal保存在一个会话中,并在稍后进行模拟之前进行检索。虽然这行得通,但不是很理想。还有另一种保存原始Windows身份的方法吗?谢谢。

使用功能:

WindowsPrincipal MyPrincipal = (WindowsPrincipal)Session["WindowsIdentity"];
WindowsIdentity wid = (WindowsIdentity)MyPrincipal.Identity;

using (WindowsImpersonationContext wic = wid.Impersonate())
{
    // Call function with impersonation
}

0 个答案:

没有答案