All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Oracle与PHP实例开发Myers订单跟踪系统_php资料_编程技术
在.Net,里用XPath的case-insensitive,的查询_.net资料_编程技术
Mssql批量修改权限_[SQL Server教程]
ASP.NET中基类页的设计和使用_[Asp.Net教程]
WebService服务和ajax使用教程_.net资料_编程技术
2003 下 IIS+PHP+MySQL+Zend Optimize_[PHP教程]
链接基准标记- base -的应用与实例_[Html教程]
在ASP.NET中利用VWD操作数据库简介_[Asp.Net教程]
asp.net2.0网站基础之创建Web窗体
visual c++工具栏的显示
Reading number is top 10 pictures
贩卖儿童者必须判死刑
随便发几张图
Chinese paper-cut grilles art appreciation6
你的钱干净吗?
西游日记3
A beautiful girl to bud1
The terra-cotta warriors3
这张图有两句话,你看出来了吗?
Wild animals melee moment of life and death2
30 beautiful school beauty6
Download software ranking
电脑知识及技巧大合集
Sora aoi's film--cangkong_Blue.Sky
Kung fu panda - the secret of the teacher
Boxer Classic video3
美女写真1
Boxer's Top ten classic battle3
Boxer vs Yellow1
Red cliff
天龙八部最新服务端
电车之狼R
delv published in(发表于) 2014/1/27 6:47:24 Edit(编辑)
asp.net,局域网存放文件_[Asp.Net教程]

asp.net,局域网存放文件_[Asp.Net教程]

asp.net 局域网存放文件_[Asp.Net教程]

1public const int LOGON32_LOGON_INTERACTIVE = 2;
2 public const int LOGON32_PROVIDER_DEFAULT = 0;
3
4 WindowsImpersonationContext impersonationContext;
5
6 [DllImport("advapi32.dll", CharSet = CharSet.Auto)]
7 public static extern int LogonUser(String lpszUserName,
8 String lpszDomain,
9 String lpszPassword,
10 int dwLogonType,
11 int dwLogonProvider,
12 ref IntPtr phToken);
13 [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
14 public extern static int DuplicateToken(IntPtr hToken,
15 int impersonationLevel,
16 ref IntPtr hNewToken);
17
18
19 private bool impersonateValidUser(String userName, String domain, String password)
20 {
21
22 IntPtr token = IntPtr.Zero;
23 IntPtr tokenDuplicate = IntPtr.Zero;
24
25 if (LogonUser(userName, domain, password, LOGON32_LOGON_INTERACTIVE,
26 LOGON32_PROVIDER_DEFAULT, ref token) != 0)
27 {
28 if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
29 {
30 WindowsIdentity tempWindowsIdentity;
31 tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
32 impersonationContext = tempWindowsIdentity.Impersonate();
33 if (impersonationContext != null)
34 return true;
35 else
36 return false;
37 }
38 else
39 return false;
40 }
41 else
42 return false;
43 }
44 private void undoImpersonation()
45 {
46 impersonationContext.Undo();//回退为未更改前账户
47 }
48
49 protected void Button1_Click(object sender, EventArgs e)
50 {
51 //临时更改为 跟 网络硬盘相同用户名密码的账户(此账户必须在网络盘有写入权限)本机也需要同样帐号密码的帐户
52
53 if (impersonateValidUser("test", "192.168.18.203", "1111"))
54 {
55 //登陆后处理密码
56 if (!Directory.Exists(@"\192.168.18.203sp est"))
57 {
58 try
59 {
60 Directory.CreateDirectory(@"\192.168.18.203sp est");
61 }
62 catch (Exception e1)
63 {
64 Response.Write(e1.Message);
65 }
66 }
67 FileUpload1.SaveAs(@"\192.168.18.203sp estq.txt");
68 undoImpersonation();
69 }
70 else
71 {
72 Response.Write("登陆失败");
73 //失败后处理密码
74 }
75 }







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.