473,412 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 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 3998
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" the authentication name and password in my php-file...
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 related topics. Here is my situation: I have a...
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 system and send a printjob under it's name to the...
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 but the information is sensitive. I thougth that...
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 credential. However, with JDBC seems I always need...
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 as they suggested. I am using DB2 jdbc on SunOS...
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 online on the hostserver is a possibility (with the...
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 away and operating exactly how I want. (With a great...
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 prompting for username and password. I just want to set...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.