婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

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

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

熱門標(biāo)簽:400電話如何申請(qǐng)取消 柳州電銷機(jī)器人公司 昆明語音電銷機(jī)器人價(jià)格 電銷語音機(jī)器人型號(hào)參數(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)問題,煩請(qǐng)?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)民參考!
  • 推薦文章
    主站蜘蛛池模板: 横山县| 南京市| 石景山区| 阜康市| 临汾市| 黄冈市| 来安县| 大邑县| 怀远县| 玛纳斯县| 台前县| 达州市| 秭归县| 都匀市| 贵溪市| 从江县| 阿克陶县| 五台县| 莎车县| 十堰市| 镇沅| 琼结县| 明水县| 新津县| 云林县| 瓦房店市| 上林县| 堆龙德庆县| 靖江市| 舞阳县| 青州市| 鄂尔多斯市| 冷水江市| 安吉县| 临西县| 宜昌市| 游戏| 通化县| 泸西县| 依兰县| 丘北县|