c# - Need suggestion for accessing remote machine in asp.net -


i want access places on remote machine.the folder want access have full control everyone. code given below used access network path.

 system.io.directoryinfo locationinfo = new system.io.directoryinfo(backuplocationtxt.text);         if (locationinfo.exists)           {             // operations          } 

the application run fine if both host computer , remote computer accessed having os windows xp .the application run fine if application running inside visual studio .

then problems ,any 1 of machine( server , remote machine)having os newer windows xp( windows 7, server 2008) locationinfo.exists false.

but if application running inside in visual studio, work fine independent of os

i searched lot in net. didnt find exact solution yet. suggests impersonation. dont know how it. impersonations solution problem ?? or there better ideas??

any appreciated

you have interesting problem, null. how have configured sites directory security? if's anonymous access enabled, folder open may not allowing access depending on os of server (see this microsoft kb article more information).

if site running anonymous, change account site runs in iis manager, or enable impersonation. when running site in visual studio site running permissions, anonymous isn't problem then.

you can use following code output identity of user site running figure out going on. may able give user site run access network location without impersonation. add asp:label page , see running as:

lblsomelabel.text = system.security.principal.windowsidentity.getcurrent().name 

impersonation open additional security risks, should more reading before making change - but, user use impersonation doesn't need domain admin. in case, user may need have full access privileges network location.

you can read more how enable impersonation on microsoft kb article. below of code page i'd recommend. rather have whole site run in impersonation mode, code below runs part having problem with.

public void page_load(object s, eventargs e) {     if(impersonatevaliduser("username", "domain", "password"))     {         //insert code runs under security context of specific user here.         undoimpersonation();     }     else     {         //your impersonation failed. therefore, include 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(); } 

also, while serching security articles found this stackoverflow question worth read.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -