【问题标题】:Either a required impersonation level was not provided, or the provided impersonation level is invalid未提供所需的模拟级别,或提供的模拟级别无效
【发布时间】:2012-08-29 00:18:52
【问题描述】:

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

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

  1. 下面的操作应该成功吗? (还是有缺陷?)
  2. 需要在 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 文件内容

回显%用户名%

【问题讨论】:

标签: c# wcf impersonation windows-security


【解决方案1】:
  1. 只要你使用 .NET Process 类,它就有缺陷,它总是以父进程的身份开始。要在另一个身份下运行它,您似乎必须使用 win32 api CreateProcessAsUser(我还没有开始工作)。

  2. 我需要以提升的权限运行它(即以管理员身份使用 Visual Studio)。

【讨论】:

    【解决方案2】:

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

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

    来源:500 Internal Server Error if the full path is not entered (0x80070542)

    【讨论】:

      猜你喜欢
      • 2020-07-14
      • 2021-02-23
      • 1970-01-01
      • 1970-01-01
      • 2020-07-07
      • 2012-01-25
      • 2011-06-17
      • 1970-01-01
      相关资源
      最近更新 更多