校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > asp.net實(shí)現(xiàn)訪問局域網(wǎng)共享目錄下文件的解決方法

asp.net實(shí)現(xiàn)訪問局域網(wǎng)共享目錄下文件的解決方法

熱門標(biāo)簽:400電話如何申請取消 柳州電銷機(jī)器人公司 昆明語音電銷機(jī)器人價(jià)格 電銷語音機(jī)器人型號參數(shù) 太原400電話上門辦理 征途美甲店地圖標(biāo)注 騰訊地圖標(biāo)注手機(jī) 百度地圖怎樣做地圖標(biāo)注 浦發(fā)電話機(jī)器人提醒還款

本文以實(shí)例講述了asp.net實(shí)現(xiàn)訪問局域網(wǎng)共享目錄下文件的解決方法,完整代碼如下所示:

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 = @"http://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(); 
  } 
}
您可能感興趣的文章:
  • jsp和asp.net共享session值示例代碼
  • ASP.NET中在不同的子域中共享Session的具體方法
  • ASP.NET+Web服務(wù)實(shí)現(xiàn)軟件共享
  • ASP.NET訪問共享文件夾的詳細(xì)步驟

標(biāo)簽:天門 白山 蘭州 陽泉 德陽 張家界 江蘇 新疆

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net實(shí)現(xiàn)訪問局域網(wǎng)共享目錄下文件的解決方法》,本文關(guān)鍵詞  asp.net,實(shí)現(xiàn),訪問,局域網(wǎng),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net實(shí)現(xiàn)訪問局域網(wǎng)共享目錄下文件的解決方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于asp.net實(shí)現(xiàn)訪問局域網(wǎng)共享目錄下文件的解決方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 南木林县| 陇川县| 牡丹江市| 北京市| 安宁市| 灵山县| 灌云县| 海阳市| 龙江县| 雷山县| 玉田县| 集贤县| 苍梧县| 黑河市| 邹城市| 林芝县| 枣庄市| 富源县| 芜湖市| 巫山县| 雷山县| 修文县| 河池市| 那坡县| 奉贤区| 尼勒克县| 车致| 海宁市| 瑞金市| 南木林县| 金湖县| 龙山县| 山东| 梧州市| 仪陇县| 满城县| 赤水市| 满洲里市| 哈巴河县| 靖江市| 温宿县|