Home All Groups Group Topic Archive Search About

How can i connect and login to Windows 2000 server from c# code?

Author
7 Oct 2005 12:18 PM
Mat
Hi!
I have the following scenario:
I want to connect to a windows 2000 "File" -server from a ASP.Net -web
application, running under network service account and create a directory on
the file server. Both the web server and the file-server is in the same
Active Directory.
Clearly, the Network service account doesnt have the right permissions to
create a directory on the file server so i have to use another account that i
have.
My problem is that i dont know how to "logon" to the windows 2000 "file"
server from my c# asp.net -code to create the directory! Any ideas?
The IT-services people running our web servers dont allow web applications
to run under other accounts!

Ps. I'm really sorry if my post is in the wrong newsgroup, but i'm new here
and can't find my way around.. Ds.

Author
7 Oct 2005 5:28 PM
BizWorld
Use NetworkCredential class to pass on the credentials that you want. OR
enable write permission on file server directory for ASP.net user and local
system account so that you can create directories under that above mentioned
directory.

Regards,

BizWorld

Show quote
"Mat" <Mats.hellstrom@newsgroups.nospam> wrote in message
news:8C6B655D-4EBE-4A61-93A0-97416434CC93@microsoft.com...
> Hi!
> I have the following scenario:
> I want to connect to a windows 2000 "File" -server from a ASP.Net -web
> application, running under network service account and create a directory
> on
> the file server. Both the web server and the file-server is in the same
> Active Directory.
> Clearly, the Network service account doesnt have the right permissions to
> create a directory on the file server so i have to use another account
> that i
> have.
> My problem is that i dont know how to "logon" to the windows 2000 "file"
> server from my c# asp.net -code to create the directory! Any ideas?
> The IT-services people running our web servers dont allow web applications
> to run under other accounts!
>
> Ps. I'm really sorry if my post is in the wrong newsgroup, but i'm new
> here
> and can't find my way around.. Ds.
Author
10 Oct 2005 11:13 AM
Mat
Thank you Bizworld for your answer,

The NetworkCredential class seems to be more directed at authenticating
towards web-based systems like web services, web sites etc.
If i choosed that way, i would have to have a web service on the "file"
-server that could take care of the directory creating business for me, and
thats not the kind of architecture i'm looking for. It would offcourse mean
installing IIS on file servers,  running web services etc etc.

In the examples that i have found, for instance the WebRequest class that
uses NetworkCredential, there has always been a (object).Credentials
-property. The DirectoryInfo class, which i intended to use, doesn't have
that. After my somewhat limited reasearch, i've come to the conclusion that
this scenario is not supported by the .NET framework and that the only way is
to use Win32 and umC++.

I really hope that i am wrong, and that someone could point me in some
direction so i could solv this in .Net instead.

Regards, Mat

Show quote
"BizWorld" wrote:

> Use NetworkCredential class to pass on the credentials that you want. OR
> enable write permission on file server directory for ASP.net user and local
> system account so that you can create directories under that above mentioned
> directory.
>
> Regards,
>
> BizWorld
>
> "Mat" <Mats.hellstrom@newsgroups.nospam> wrote in message
> news:8C6B655D-4EBE-4A61-93A0-97416434CC93@microsoft.com...
> > Hi!
> > I have the following scenario:
> > I want to connect to a windows 2000 "File" -server from a ASP.Net -web
> > application, running under network service account and create a directory
> > on
> > the file server. Both the web server and the file-server is in the same
> > Active Directory.
> > Clearly, the Network service account doesnt have the right permissions to
> > create a directory on the file server so i have to use another account
> > that i
> > have.
> > My problem is that i dont know how to "logon" to the windows 2000 "file"
> > server from my c# asp.net -code to create the directory! Any ideas?
> > The IT-services people running our web servers dont allow web applications
> > to run under other accounts!
> >
> > Ps. I'm really sorry if my post is in the wrong newsgroup, but i'm new
> > here
> > and can't find my way around.. Ds.
>
>
>
Author
10 Oct 2005 1:13 PM
Bjarke Lindberg
Mat wrote:
>
> I really hope that i am wrong, and that someone could point me in some
> direction so i could solv this in .Net instead.

You may look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconimpersonatingreverting.asp

/B
Author
11 Oct 2005 3:01 AM
Peter Huang" [MSFT]
Hi

Based on my understanding, you want to call the Directory.CreateDirectory
on a file server in a ASP.NET application which ran under the
network_service account.
e.g.
Directory.CreateDirectory(@"\\fileserver\test\createddir");

Since your two machine is in the same Domain, I think you may try to add
the domain\fileserver account into the Test folder share permission list,
so that
domain\fileserver will have the permission to create dir.

When ASP.NET app run under network_service account, it is using the machine
account,  domain\fileserver to do the job.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

AddThis Social Bookmark Button