File Access via the Web

D

Dave

I have a web app that needs to access a folder on a different server.
The other server "IS" on a domain. I tried using DirectoryInfo, even
with a Virtual Directory, only to find that it pertains to the local
box. Can anyone point me in the direction of being able to access the
file struction on another server?

Thanks
 
A

Alberto Poblacion

Dave said:
I have a web app that needs to access a folder on a different server.
The other server "IS" on a domain. I tried using DirectoryInfo, even
with a Virtual Directory, only to find that it pertains to the local
box. Can anyone point me in the direction of being able to access the
file struction on another server?

The key is using adequate credentials. The web application (which I
assume is an asp.net application since you are asking in a C# group) is
going to be running under the identity of the asp.net worker process, which
is a local account and most likely will not be able to access the folder on
the other server. To override this behaviour, you can add an <identity
impersonate="true" ... /> directive to your web.config. You can either
specify a userName and password in this directive, or you can omit it and
asp.net will inherit the identity from IIS (which you can configure as
needed, for instance, you can use integrated authentication to use the
identity of the user that is browsing). Whatever combination you choose, the
final identity that you are using should be granted access permissions to
the folder that you want to browse. Note that if you are going to use
integrated authentication on IIS, and you want that user to access a second
server, there are some requirements that need to be fulfilled from a systems
administration point of view (the server needs to be trusted for
delegation). This is outside of the scope of the questions that can be
answered in a C# forum; if you need to do this, it's better to ask in a
Windows Server forum. See this article:
http://msdn.microsoft.com/en-us/library/ms998351.aspx .

If you don't want to use the asp.net identity as outlined above, an
alternative is to impersonate the user in your code before attempting to
access the remote folder. There are examples on how to do it in MSDN:
http://support.microsoft.com/kb/306158

Once you are using the correct credentials, either System.IO.Directory
(static methods) or DirectoryInfo (instance methods) should be able to
access the remote folder as @"\\server\folder".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top