473,545 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\s hareFolder");

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.Netw orkCredential myCredentials = new
System.Net.Netw orkCredential(" ","","");
myCredentials.D omain = "";
myCredentials.U serName = "username";
myCredentials.P assword = "password";
Uri myUrl=new Uri("file://remoteNetwork/shareFolder/New Text
Document.txt");
WebRequest myWebRequest = WebRequest.Crea te(myUrl);
Console.WriteLi ne("\n\nReques t to Url is sent.Waiting for
response...Plea se wait ...");
CredentialCache wrCache = new CredentialCache ();
wrCache.Add(myU rl,"NTLM", myCredentials);
myWebRequest.Cr edentials = wrCache;
myWebRequest.Pr eAuthenticate = true;
wp.Credentials = wrCache;
WebResponse myWebResponse = myWebRequest.Ge tResponse();
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
NetworkCredenti al 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 4008
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.goo glegroups.com.. .
I am writing some code to access share folder on a remote network.
DirectoryInfo dicInfo = new DirectoryInfo(" remoteNetwork\s hareFolder");

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.Netw orkCredential myCredentials = new
System.Net.Netw orkCredential(" ","","");
myCredentials.D omain = "";
myCredentials.U serName = "username";
myCredentials.P assword = "password";
Uri myUrl=new Uri("file://remoteNetwork/shareFolder/New Text
Document.txt");
WebRequest myWebRequest = WebRequest.Crea te(myUrl);
Console.WriteLi ne("\n\nReques t to Url is sent.Waiting for
response...Plea se wait ...");
CredentialCache wrCache = new CredentialCache ();
wrCache.Add(myU rl,"NTLM", myCredentials);
myWebRequest.Cr edentials = wrCache;
myWebRequest.Pr eAuthenticate = true;
wp.Credentials = wrCache;
WebResponse myWebResponse = myWebRequest.Ge tResponse();
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
NetworkCredenti al 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
13166
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 or can I use for example a html form/mysql authentication and at the same time set some variables or headers (or something) so the user can access...
4
41294
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 Access 2000 .mdb file which has several linked tables to a ODBC data source, namely an Oracle back-end. I have already setup the connctions to these...
8
6708
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 printqueue. This is why I created a program that picks the username out for the .PRN file, creates a local user, copies the PRN file the network...
2
6658
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 if I do Windows Authentication, would be the most secure one. I'm not sure if this is true. In any event, I want to avoid the browser asking for...
3
10214
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 to provide username and password, the Java API DriverManger.getConnection(String url) does not work. I am not sure if this is because the JDBC...
2
5949
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 5.8 with db2 version 7.2.0. When I am using the type2 network driver (COM.ibm.db2.jdbc.net.DB2Driver) with username and password, everything is...
3
2467
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 program PLESK) to make a directory secure (to access a page in that directory, you have to give a username and a
10
2223
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 deal of help from you fine people at theScripts--thank you!) So the time finally arrived to put my form on the network and allow other people to...
1
1525
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 Username and password authentication whenever an user accessing a system in LAN.Can anyone help me to solve this?
0
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7446
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7778
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3476
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.