gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 18:36:03 25 4
gpt4 key购买 nike

我在 WCF 服务和模拟方面遇到了一些问题,我在下面将其提炼为一个简单的方法。 WCF 服务目前在 exe 中自行托管。异常消息是“没有提供所需的模拟级别,或者提供的模拟级别无效”。检查何时抛出错误,Identity ImpersonationLevel 设置为委托(delegate),如我的客户端所指定,并通过 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 文件内容

echo %username%

最佳答案

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

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

关于c# - 未提供所需的模拟级别,或者提供的模拟级别无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12261789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com