微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

>下面的操作应该成功吗? (或者它有缺陷吗?)
>需要在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%

解决方法

>只要您使用.NET Process类,它就会有缺陷,它始终以父进程的标识开头.要在另一个身份下运行它,看起来你必须使用win32 api CreateProcessAsUser(我还没有工作). >我需要提升它(即Visual Studio作为管理员).

原文地址:https://www.jb51.cc/csharp/99915.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐