472,353 Members | 1,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Bypass username/password dialog when accessing remote network

I am writing some code to access share folder on a remote network.
DirectoryInfo dicInfo = new DirectoryInfo("remoteNetwork\shareFolder");

if (dicInfo.Exists)
{
//application code followed

}
The problem is when I ran this code, it always give me dicInfo.Exists =
false even though the directory did exists. If I go to Start\Run\ and
type in \\remoteNetWork\shareFolder, a dialog will pop up ask me for
username/password. After that if I run the code again and
dicInfo.Exists = true, which means the username/password has been
cached somewhere.
I also try to use WebRequest class but with no success:
System.Net.NetworkCredential myCredentials = new
System.Net.NetworkCredential("","","");
myCredentials.Domain = "";
myCredentials.UserName = "username";
myCredentials.Password = "password";
Uri myUrl=new Uri("file://remoteNetwork/shareFolder/New Text
Document.txt");
WebRequest myWebRequest = WebRequest.Create(myUrl);
Console.WriteLine("\n\nRequest to Url is sent.Waiting for
response...Please wait ...");
CredentialCache wrCache = new CredentialCache();
wrCache.Add(myUrl,"NTLM", myCredentials);
myWebRequest.Credentials = wrCache;
myWebRequest.PreAuthenticate = true;
wp.Credentials = wrCache;
WebResponse myWebResponse = myWebRequest.GetResponse();
The exception is thrown at the last line. It is either access is denied

or bad username or password. I also try to change "NTLM" to "Basic"
with no success. If I provide username, password in a dialog as the
above case, the code then work just fine. It means that the
NetworkCredential doesn't even need to do its work.
It is essential for my application to provide username/password behind
the scene because user is not always there to provide it. Any help/
guidance is appreciated.

Nov 19 '05 #1
1 3928
Give the ASP.NET account access to the share folder or use Impersonation to
impersonate a user with access to the share (like the username and password
you provide dialog box).

Shawn

<th******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I am writing some code to access share folder on a remote network.
DirectoryInfo dicInfo = new DirectoryInfo("remoteNetwork\shareFolder");

if (dicInfo.Exists)
{
//application code followed

}
The problem is when I ran this code, it always give me dicInfo.Exists =
false even though the directory did exists. If I go to Start\Run\ and
type in \\remoteNetWork\shareFolder, a dialog will pop up ask me for
username/password. After that if I run the code again and
dicInfo.Exists = true, which means the username/password has been
cached somewhere.
I also try to use WebRequest class but with no success:
System.Net.NetworkCredential myCredentials = new
System.Net.NetworkCredential("","","");
myCredentials.Domain = "";
myCredentials.UserName = "username";
myCredentials.Password = "password";
Uri myUrl=new Uri("file://remoteNetwork/shareFolder/New Text
Document.txt");
WebRequest myWebRequest = WebRequest.Create(myUrl);
Console.WriteLine("\n\nRequest to Url is sent.Waiting for
response...Please wait ...");
CredentialCache wrCache = new CredentialCache();
wrCache.Add(myUrl,"NTLM", myCredentials);
myWebRequest.Credentials = wrCache;
myWebRequest.PreAuthenticate = true;
wp.Credentials = wrCache;
WebResponse myWebResponse = myWebRequest.GetResponse();
The exception is thrown at the last line. It is either access is denied

or bad username or password. I also try to change "NTLM" to "Basic"
with no success. If I provide username, password in a dialog as the
above case, the code then work just fine. It means that the
NetworkCredential doesn't even need to do its work.
It is essential for my application to provide username/password behind
the scene because user is not always there to provide it. Any help/
guidance is appreciated.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Marko Lahtinen | last post by:
Hello! A part of my website is protected with a .htaccess file. Can I somehow bypass the username/password dialog ?? Can I somehow "hardcode"...
4
by: Jean | last post by:
Hi everyone, I was hoping somebody could assist me in this issue. I am quite a newbie to ODBC connections and was struggling to search for...
8
by: Philip Wagenaar | last post by:
I need to send printjobs to a printqueue under diffrent usernames. The printsoftware on the queue is not very 'secure' so I can create a user on 1...
2
by: Frank | last post by:
Hi, I wasn't sure which group to use but I'm developing a web application that connects to a sql server. This application is for External Clients...
3
by: %NAME% | last post by:
When using embedded SQL for db2 under solaris, you do not need to give username and password since the system will use your unix-login as default...
2
by: %NAME% | last post by:
(Thanks to Bernd, Ian, Phil last time for their detailed answers last time) Now I try to call JDBC driver without giving the username and password...
3
by: Charlotte | last post by:
Hello, info: I'me a rookie with IIS I have on a WinXP Pro the IIS installed, so I can test some pages before uploading to the hostserver...
10
by: nickvans | last post by:
Hi all, After several months of development (I was totally new to SQL, VBA and MS Access when I started) I finally have my database all squared...
1
by: rajendran1983 | last post by:
I have windows XP pro systems with network having workgroup. i dont have domain. If am accesing a system from my workgroup its opening without...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.