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",...