ASP. NET Access Network path method (impersonate user login), ASP. _php Tutorial

Source: Internet
Author: User

ASP. NET Access Network path method (impersonate user login), ASP.


Core code:

public class identityscope:idisposable{//obtains user token [DllImport ("advapi32.dll", SetLastError = True)] static extern bool LogonUser (string pszusername, String pszdomain, String pszpassword,int dwlogontype, int dwlogonprovide    R, ref IntPtr Phtoken); Closes open handes returned by LogonUser [DllImport ("kernel32.dll", CharSet = CharSet.Auto)] extern static bool C    Losehandle (IntPtr handle);    [DllImport ("Advapi32.DLL")] static extern bool ImpersonateLoggedOnUser (IntPtr htoken);    [DllImport ("Advapi32.DLL")] static extern bool RevertToSelf ();    const int logon32_provider_default = 0; const int logon32_logon_newcredentials = 9;//domain Ò control d? need to è for a use?: I    Nteractive = 2 private bool disposed; ////// record? /// ///With the name of the family?///Domain Ò name????? in Ú domain Ò D í make 1 use machine ú to ÷IP///Secret u code?    Public Identityscope (String susername, String Sdomain, String spassword) {//Initialize tokens INTPTR PE      Xistingtokenhandle = new IntPtr (0);      IntPtr pduplicatetokenhandle = new IntPtr (0); try {//Get handle to token bool bimpersonated = LogonUser (sUserName, Sdomain, Spassword,logon32_logon        _newcredentials, Logon32_provider_default, ref pexistingtokenhandle); if (true = = bimpersonated) {if (!            ImpersonateLoggedOnUser (Pexistingtokenhandle)) {int nerrorcode = Marshal.GetLastWin32Error (); throw new Exception ("ImpersonateLoggedOnUser error;          Code= "+ nerrorcode);          }} else {int nerrorcode = Marshal.GetLastWin32Error (); throw new Exception ("LogonUser error;        Code= "+ nerrorcode); }} finally {//close handle (s) if (pexistingtokenhandle! = IntPtr.Zero) Closehandl        E (Pexistingtokenhandle); if (pduplicatEtokenhandle! = IntPtr.Zero) CloseHandle (Pduplicatetokenhandle);        }} protected virtual void Dispose (bool disposing) {if (!disposed) {RevertToSelf ();      disposed = true;    }} public void Dispose () {Dispose (true); }  }

The second parameter is the domain name, the domain name, write the domain name, no domain name to write the target machine IP can be

using (identityscope c = new Identityscope ("Administrator", "192.168.0.1", "11111")) {string[] filelist = System.IO.Direc Tory. GetDirectories (@ "\\192.168.0.1\folderName");}

ASPNET Impersonation User logon issue

You can configure it in Web. config.


ASPNET-related, the user is logged in, how to prevent by copying a work can be a page path, access to the page he does not have access to, I used the master

You can try to make a table, save the page name, a save user, and then another relationship table, page number and user number

http://www.bkjia.com/PHPjc/865253.html www.bkjia.com true http://www.bkjia.com/PHPjc/865253.html techarticle ASP. NET Access Network path method (impersonate user login), asp: public class identityscope:idisposable{//obtains user token [DllImport ( "Advapi32.dll",...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.