长理培训真题库
我的
军队文职考试一本通

asp.net实现访问局域网共享目录下文件教程

2020-01-21 11:10
方法步骤 using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.IO; using System.Security.Principal; using System.Runtime.InteropServices; public partial class _Default : System.Web.UI.Page { public const int LOGON32_LOGON_INTERACTIVE = 2; public const int LOGON32_PROVIDER_DEFAULT = 0; WindowsImpersonationContext impersonationContext; [DllImport("advapi32.dll")] public static extern int LogonUserA(String lpszUserName, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken); [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern int DuplicateToken(IntPtr hToken, int impersonationLevel, ref IntPtr hNewToken); [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool RevertToSelf(); [DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern bool CloseHandle(IntPtr handle); public void Page_Load(Object s, EventArgs e) { if (impersonateValidUser("lucas", "Workgroup", "lcas")) { string path = @"//zhehui001/lu"; foreach (string f in Directory.GetFiles(path)) { Response.Write(f); } undoImpersonation(); } else { //Your impersonation failed. Therefore, include a fail-safe mechanism here. } } private bool impersonateValidUser(String userName, String domain, String password) { WindowsIdentity tempWindowsIdentity; IntPtr token = IntPtr.Zero; IntPtr tokenDuplicate = IntPtr.Zero; if (RevertToSelf()) { if (LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token) != 0) { if (DuplicateToken(token, 2, ref tokenDuplicate) != 0) { tempWindowsIdentity = new WindowsIdentity(tokenDuplicate); impersonationContext = tempWindowsIdentity.Impersonate(); if (impersonationContext != null) { CloseHandle(token); CloseHandle(tokenDuplicate); return true; } } } } if (token != IntPtr.Zero) CloseHandle(token); if (tokenDuplicate != IntPtr.Zero) CloseHandle(tokenDuplicate); return false; } private void undoImpersonation() { impersonationContext.Undo(); } } 补充:局域网、校园网安全维护方法 校园网络分为内网和外网,就是说他们可以上学校的内网也可以同时上 互联网,大学的学生平时要玩游戏购物,学校本身有自己的服务器需要维护; 在大环境下,首先在校园网之间及其互联网接入处,需要设置防火墙设 备,防止外部攻击,并且要经常更新抵御外来攻击; 由于要保护校园网所有用户的安全,我们要安全加固,除了防火墙还要 增加如 ips,ids 等防病毒入侵检测设备对外部数据进行分析检测,确保校园 网的安全; 外面做好防护措施,内部同样要做好防护措施,因为有的学生电脑可能 带回家或者在外面感染,所以内部核心交换机上要设置 vlan 隔离,旁挂安全 设备对端口进行检测防护; 内网可能有 ddos 攻击或者 arp 病毒等传播,所以我们要对服务器或者 电脑安装杀毒软件,特别是学校服务器系统等,安全正版安全软件,保护重 要电脑的安全; 对服务器本身我们要安全 server 版系统,经常修复漏洞及更新安全软件, 普通电脑一般都是拨号上网,如果有异常上层设备监测一般不影响其他电脑 。 做好安全防范措施,未雨绸缪。
温馨提示:如果当前文档预览出现乱码或未能正常浏览,请先下载原文档进行浏览。
asp.net实现访问局域网共享目录下文件教程 第 1 页

下载提示

1 该文档不包含其他附件(如表格、图纸),本站只保证下载后内容跟在线阅读一样,不确保内容完整性,请务必认真阅读

2 除PDF格式下载后需转换成word才能编辑,其他下载后均可以随意编辑修改

3 有的标题标有”最新”、多篇,实质内容并不相符,下载内容以在线阅读为准,请认真阅读全文再下载

4 该文档为会员上传,版权归上传者负责解释,如若侵犯你的隐私或权利,请联系客服投诉

最近更新

热门排行