• λ我爱Aspx >> C#.Net >> 通过.NET Framework访问活动目录(2)
  • 通过.NET Framework访问活动目录(2)

  • :aspxer  Դ:internet  :2007-5-20 15:38:39  ؼ:.net
  • [DllImport("advapi32.dll", CharSet=CharSet.Auto)]public static extern int

    LogonUser(String lpszUserName,

    String lpszDomain,String lpszPassword,int dwLogonType,int dwLogonProvider,

    ref IntPtr phToken);

    [DllImport("advapi32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto,

    SetLastError=true)]public

    extern static int DuplicateToken(IntPtr hToken, int impersonationLevel,

    ref IntPtr hNewToken);

    #endregion

    图1.5 建立扮演

    首先,我们需要从advapi32.dll中导入新的方法,其中包括一些有用的常量。名字为impersonationContext的变量将用来保持扮演操作之前的Windows用户。

    这样,我们就建立了扮演,下面是一个如何使用它的例子:

    if(impersonateValidUser(this.LoginUsername, this.DomainName,

    this.loginPassword)) {

    //在这里插入在指定用户的安全环境下运行的代码

    //不要忘记取消扮演

    undoImpersonation();

    } else {

    //扮演操作失败了,插入保证失败后系统安全的机制

    Ҷƪл˵?
  • һƪ在Linux上运行C#
    һƪ概述C#中的索引器