C# 未提供所需的模拟级别,或者提供的模拟级别无效

C# 未提供所需的模拟级别,或者提供的模拟级别无效,c#,wcf,impersonation,windows-security,C#,Wcf,Impersonation,Windows Security,我在WCF服务和模拟方面遇到了一些问题,我将其提炼为下面的一个简单方法。WCF服务当前在exe中自托管。异常消息为“未提供所需的模拟级别,或者提供的模拟级别无效”。检查抛出错误时,Identity ImpersonationLevel设置为delegation,这是在我的客户端上指定的,并通过Kerberos对其进行身份验证 我有点困惑,因为在我看来,模拟级别和身份验证的要求已经满足了。我的想法是,问题可能与域设置有关,我已经设置并认为设置正确。所以我有两个问题: 下面的操作是否成功?(还是有缺

我在WCF服务和模拟方面遇到了一些问题,我将其提炼为下面的一个简单方法。WCF服务当前在exe中自托管。异常消息为“未提供所需的模拟级别,或者提供的模拟级别无效”。检查抛出错误时,Identity ImpersonationLevel设置为delegation,这是在我的客户端上指定的,并通过Kerberos对其进行身份验证

我有点困惑,因为在我看来,模拟级别和身份验证的要求已经满足了。我的想法是,问题可能与域设置有关,我已经设置并认为设置正确。所以我有两个问题:

  • 下面的操作是否成功?(还是有缺陷?)
  • 需要在Win2k8域上配置哪些设置才能使其正常工作?我正在处理两个盒子,它们是同一个Win2k8域的成员(这是一个新域,非常普通,目的是测试模拟)
  • 代码如下:

    [OperationBehavior(Impersonation = ImpersonationOption.Required)]
    public string Test()
    {
        WindowsIdentity identity = ServiceSecurityContext.Current.WindowsIdentity;
        using (identity.Impersonate())
        {
            ProcessStartInfo pi = new ProcessStartInfo(@"c:\temp\test.bat");
            pi.UseShellExecute = false;
            pi.RedirectStandardOutput = true;
            Process p = Process.Start(pi); // exception thrown here!
            p.WaitForExit();
            string o = p.StandardOutput.ReadToEnd();
            return o;
        }
    }
    
    例外情况详情:

    Win32Exception occurred: Either a required impersonation level was not provided, or the provided impersonation level is invalid
       at System.Diagnostics.Process.CreatePipeWithSecurityAttributes(SafeFileHandle& hReadPipe, SafeFileHandle& hWritePipe, SECURITY_ATTRIBUTES lpPipeAttributes, Int32 nSize)
       at System.Diagnostics.Process.CreatePipe(SafeFileHandle& parentHandle, SafeFileHandle& childHandle, Boolean parentInputs)
       at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
       at System.Diagnostics.Process.Start()
       at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
       at MonetEnterprise.Service.SecurityService.Test()
    
    Test.bat文件内容

    回显%username%

  • 它是有缺陷的,只要您使用.NET Process类,它总是从父进程的标识开始。要在另一个身份下运行它,看起来您必须使用win32 api CreateProcessAsUser(我还没有使用它)

  • 我需要将其提升运行(即Visual Studio作为管理员)


  • 这解决了我的应用程序的问题:

  • 转到开始>设置>控制面板>管理工具>本地安全策略 展开本地策略并选择用户权限分配
  • 在右侧窗格中,双击“身份验证后模拟客户端”
  • 在“安全策略设置”对话框中,单击“添加用户或组”
  • 在“选择用户、计算机或组”对话框中,键入
    IIS\u IUSRS
  • 选择检查名称并验证名称是否正确

  • 来源:

    使用调试器在进入
    使用
    块之前,
    identity
    等于什么?Hi@rahmhund,这是客户端的登录-这是您期望的,对吗?默认情况下,NT域中禁用委派。如果是必需的(看起来是),则必须启用它。看到或