Unkown username or bad password error accessing shared drive from IIS

381 views Asked by At

I am trying to read files from a shared drive. The share is password protected so I am first using a net use command to access the share and then reading the files.

Here is the net use command I am using:

net use "\server\share\folder name" /u:"domain\username" "password"

This was all working fine when debugging from VS2010. Once I published to IIS 6 though, it started giving me an error: Login Failure: Unkown username or bad password.

I've read up alot about this and it seems that this issue comes mostly from the accounts not matching up. I am running my service under ASPNET account (annonymous authentication is enabled) but I can't see why this should make a difference being that I am passing a username and password through the net use command.

I am a bit lost with how this all works so if anyone can clarify, I'd really appreciate it. TIA!

1

There are 1 answers

0
tdelepine On

few a month ago i was the similar problem. I found a library on the net that you can use for resolved your issue.

Search "PInvokeWindowsNetworking" cs file on google and now my code it's very simple to using it

string v_DirectoryName = .... //Your Network directory
    PinvokeWindowsNetworking.connectToRemote(v_DirectoryName.DirectoryName, ConfigurationManager.AppSettings["TransmissionDirectoryLogin"], ConfigurationManager.AppSettings["TransmissionDirectoryPassword"]);
        DirectoryInfo v_Directory = new DirectoryInfo(v_DirectoryName);
        ....//Manage your file and directory access
    PinvokeWindowsNetworking.disconnectRemote(v_DirectoryName.DirectoryName);