0

I have searched through web and tried all possible solution but my web app failed every time ! I have bunch of shared drive paths which I want to access through Web app. I have credentials to access this shared drive paths. The possible solution I found was enable identity impersonate but my web app is failing me in that case. I tried accessing it Using UNC API but that is failing too. I have been told that I can access this shared drives as directory service (dont need to use UNC API). Share your thoughts if you have any ! Thank you!

Enable Identity Impersonate

In Web.Config

<identity impersonate="true" userName="username" password="pass">

and it is not able to locate my project when I am enabling identity impersonate --Gives System.IO.DirectoryNotFoundException

(tried changing authentication mode(Windows,None,etc) in web.config -- same above error)

UNC Access

I took a copy of UNCAccessWithCredentials from here

https://www.codeproject.com/Articles/43091/Connect-to-a-UNC-Path-with-Credentials

using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials()) 
//access network drives through functional id 
{ 

try
{
if (unc.NetUseWithCredentials(sharedrive, functionalID, domainName, 
functionalPass))
{ 
string[] files = Directory.GetFiles(sharedrive);
}
}
}

It throws error 87 inside NetUseWithCredentials() method

vee
  • 11
  • 3
  • When I see something like this, my first question is: why do you need to access an internal remote network location from your web application? You're opening yourself up to performance issues and failures that are difficult to debug. – AJ X. Aug 10 '17 at 14:05
  • You can use the FileWebRequest from System.net namespace and DirectoryInfo class read it. I haven't tried it but it should work. – CodeWeed Aug 10 '17 at 14:09
  • DirectoryInfo class to get the information on network drive. – CodeWeed Aug 10 '17 at 14:15
  • So, what do you mean "failing me", what error message(s) do you get? If you post your code someone may be better able to help you. – Joshua Drake Aug 10 '17 at 15:22
  • @ Joshua Drake -It is not able to find the path of an application upon enabling identity impersonate ---- System.IO.DirectoryNotFoundException – vee Aug 10 '17 at 15:47
  • @CodeWeed There is no such property for directory info so that it can take credentials and validate the path @ axlj - I understand your point but that is the requirement of the application to perform certain tasks on shared drive records through web application – vee Aug 10 '17 at 15:48
  • Please Note that I have not deployed it once ! It is running in my local system right now but I am giving identity impersonate credentials same as local user (Not as any other user)right now and still it could not locate my project – vee Aug 10 '17 at 16:01
  • @vee If it were me, I would rewrite my question to focus on one of the solutions I tried, and give as much details as possible about that scenario (what worked, what didn't; what code I used). If that doesn't work, ask about a different solution, with a different question. – jpaugh Aug 10 '17 at 17:12
  • If you log onto your (dev) PC with those impersonated credentials [username] [pass], can you connect to your UNC destination? Start there, to confirm that permissions are correct, first. – tgolisch Aug 10 '17 at 18:55
  • @tgolisch - In that case ,I can access the UNC path (which i have access) without providing any credentials – vee Aug 10 '17 at 19:08
  • Possible duplicate of [Access files from network share in c# web app](https://stackoverflow.com/questions/29346/access-files-from-network-share-in-c-sharp-web-app) – tgolisch Aug 10 '17 at 19:38

0 Answers0