我爱Aspx >> C#.Net >> 通过.NET Framework访问活动目录(2)[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 {
//扮演操作失败了,插入保证失败后系统安全的机制
Ҷƪл˵?
从Windows DNA到.NET(3)[05-20]
从Windows DNA到.NET(2)[05-20]
从Windows DNA到.NET(1)[05-20]
微软公布“.NET”第二阶段研发方..[05-20]
另类.NET编程语言之旅[05-20]
.NETFramework发现漏洞 可能导致..[05-20]
.Net中如何操作IIS(原理篇)[05-20]
使用.NET Framework 进行事务处理[05-20]
.NET并不一定全是新东西[05-20]
Visual C#.Net网络程序开发-Tcp篇..[05-20]
概述C#中的索引器[05-20]
轻松访问系统资源[05-20]
C#锐利体验(8.2)[05-20]
C#锐利体验(8.1)[05-20]
C#锐利体验(7.1)[05-20]
C#锐利体验(6.4)[05-20]
C#锐利体验(6.2)[05-20]
C#锐利体验(6.1)[05-20]
运用C#实现POP3邮件接收程序(1)[05-20]
Visual C#中使用线程(3)[05-20]