Click to See Complete Forum and Search --> : connecting to user/password protected server


Matthew.Cross
April 22nd, 2008, 09:17 AM
Hi, i have written an app that needs to connect to a server that has access rights associated with it. If i am logged on as a certain person who has access privaleges there is not a problem. In certain circumstances the computer running my app has not network connection to a domain. I have programmed access to the domain but the server i need to access data on in the domain is user and password protected. If i use the following code i cannot access the file.

using (StreamReader sr = new StreamReader("\\\\Ukptserver03\\Archive\\Users.Dat"))
{
String line;
while ((line = sr.ReadLine()) != null)
{
.....etc

Are there any other parameters i need to pass to the streamreader or do i need to set something else up.

Thanks.

MikeVallotton
April 22nd, 2008, 10:14 AM
Here's an article showing you how to impersonate a specific user in code.

http://support.microsoft.com/?id=306158#4

If you throw an exception, whatever code catches it will also run in that security context, so watch out for that.

Matthew.Cross
April 23rd, 2008, 01:05 AM
Here's an article showing you how to impersonate a specific user in code.

http://support.microsoft.com/?id=306158#4

If you throw an exception, whatever code catches it will also run in that security context, so watch out for that.

Thanks for this, it is very helpful.