I'm attempting to connection to a network resource from an internal website with alternate credentials.
[DllImport("Mpr.dll")]
private static extern int WNetAddConnection2(
NETRESOURCE lpNetResource,
string lpPassword,
string lpUserID,
int dwFlags
);
private void UseConnection(string username, string password)
{
var resource = new NETRESOURCE();
resource.dwType = RESOURCETYPE_DISK;
resource.lpRemoteName = this._uncPath;
Internals.Logging.Log.Info(string.Format("Connecting to resource '{0}'...", resource.lpRemoteName));
int ret = -1;
ret = WNetAddConnection2(resource, password, username, 0);
if (ret != NO_ERROR)
{
WNetCancelConnection2(this._uncPath, CONNECT_UPDATE_PROFILE, true);
throw new AccessViolationException(GetErrorForNumber(ret));
}
}
This is an internal asp.net website which is attempting to connection to a Linux SAMBA share to create a file.
When I attempt to call UseConnection() I get the error
System.AccessViolationException: Error: Unknown, 86
I'm having difficulty running down the meaning of this error or what is causing it.
The website is using Windows / NTLM authentication (no basic or anonymous access).