没有提供所需的模拟级别,或者提供的模拟级别无效

问题描述 投票:8回答:2

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

我有点不解,因为在我看来满足了ImpersonationLevel和Authenticaiton的要求。我的想法是问题可能与域设置有关,我已经设置并认为设置正确。所以我有两个问题:

  1. 以下操作应该成功吗? (还是有缺陷?)
  2. 需要在Win2k8域上配置哪些设置才能使其正常工作?我正在使用两个框,它们是同一个Win2k8域的成员(它是一个新域,并且具有相当的香草味,目的是测试模拟)。
  3. 代码如下:

[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文件的内容

echo%username%

我在使用WCF服务和模拟时遇到一些问题,下面将其简化为一种简单的方法。 WCF服务当前是自托管在exe中的。异常消息是“要么...

c# wcf impersonation windows-security
2个回答
7
投票
  1. 只要您使用.NET Process类,它就有缺陷,它将始终以父进程的身份开头。要以其他身份运行它,您似乎必须使用win32 api CreateProcessAsUser(我还没有工作)。


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.