PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 3.67 average.

Directory.GetFiles() / DirectoryInfo.GetFiles() on a remote server

 
 
=?Utf-8?B?RGFuaWVsIENvcnLDqmE=?=
Guest
Posts: n/a
 
      22nd Mar 2007
Hi,

I've been trying to use Directory.GetFiles() and also
DirectoryInfo.GetFiles() to list files on a remote server using
"\\server_name\dir_name" like paths. It works fine on a test windows app, but
I get an access error message when the code is running on a asp.net app.

First I thought it was just a matter of credentials, so I started to use
windows authentication and impersonate the current user, but I still got the
same message.

Any thoughts? Is it possible to list files on a remote server when code is
running on an asp.net app?


Regards,
Daniel
 
Reply With Quote
 
 
 
 
Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
Guest
Posts: n/a
 
      22nd Mar 2007
Are you sure the user you're impersonating has permission to that server and
file share?
To rule out credential issues once and for all I think you should try
impersonation using your user account since you know for sure that you have
access.

For example, you can add a line similar to this to your web.config file:
<identity impersonate="true" userName="domain\MyUserName">
password="MyPassword"/>

Here's more info on impersonation:
http://msdn.microsoft.com/library/de...ersonation.asp

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net



"Daniel Corrêa" <Daniel Corrê(E-Mail Removed)> wrote in message
news:CF21102E-9410-4CFA-B1A7-(E-Mail Removed)...
> Hi,
>
> I've been trying to use Directory.GetFiles() and also
> DirectoryInfo.GetFiles() to list files on a remote server using
> "\\server_name\dir_name" like paths. It works fine on a test windows app,
> but
> I get an access error message when the code is running on a asp.net app.
>
> First I thought it was just a matter of credentials, so I started to use
> windows authentication and impersonate the current user, but I still got
> the
> same message.
>
> Any thoughts? Is it possible to list files on a remote server when code is
> running on an asp.net app?
>
>
> Regards,
> Daniel


 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGFuaWVsIENvcnLDqmE=?=
Guest
Posts: n/a
 
      24th Mar 2007
Hi Steve,

Thanks for you help. A really strange thing happened. When I used the
userName and password parameters it worked fine. Then I removed these
parameters and logged in with the same user name and password. Although I
could see that the user was the same, it didn't work.

This is the test code I'm using:

Response.Write(WindowsIdentity.GetCurrent().Name + "<br />");
string[] files = Directory.GetFiles("\\\\ecomponentdc\\Temp");
if(files != null && files.Length > 0)
foreach(string filePath in files)
Response.Write(filePath + "<br />");

And this is the result with and without the web.config parameters:

-> With web.config parameters
E-COMPONENT\daniel.correa
\\ecomponentdc\Temp\New Text Document.txt

-> No web.config parameters
E-COMPONENT\daniel.correa
Access to the path "\\ecomponentdc\Temp" is denied.

As you can see, both times the same user was impersonated, so why didn't it
work the second time? Could there be an IIS configuration, or could it be CAS
related? Any ideas?

Thanks again for your help,
Daniel




"Steve C. Orr [MCSD, MVP, CSM, ASP Inside" wrote:

> Are you sure the user you're impersonating has permission to that server and
> file share?
> To rule out credential issues once and for all I think you should try
> impersonation using your user account since you know for sure that you have
> access.
>
> For example, you can add a line similar to this to your web.config file:
> <identity impersonate="true" userName="domain\MyUserName">
> password="MyPassword"/>
>
> Here's more info on impersonation:
> http://msdn.microsoft.com/library/de...ersonation.asp
>
> --
> I hope this helps,
> Steve C. Orr,
> MCSD, MVP, CSM, ASPInsider
> http://SteveOrr.net
>
>
>
> "Daniel Corrêa" <Daniel Corrê(E-Mail Removed)> wrote in message
> news:CF21102E-9410-4CFA-B1A7-(E-Mail Removed)...
> > Hi,
> >
> > I've been trying to use Directory.GetFiles() and also
> > DirectoryInfo.GetFiles() to list files on a remote server using
> > "\\server_name\dir_name" like paths. It works fine on a test windows app,
> > but
> > I get an access error message when the code is running on a asp.net app.
> >
> > First I thought it was just a matter of credentials, so I started to use
> > windows authentication and impersonate the current user, but I still got
> > the
> > same message.
> >
> > Any thoughts? Is it possible to list files on a remote server when code is
> > running on an asp.net app?
> >
> >
> > Regards,
> > Daniel

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An error has occurred while establishing a connection to the server.When connecting to SQL Server 2005, this failure may be caused by the factthat under the default settings SQL Server does not allow remote connections. mina Microsoft Dot NET 0 8th Oct 2008 07:11 AM
Help. Getting a An error has occurred while establishing a connectionto the server. When connecting to SQL Server 2005, this failure may be causedby the fact that under the default settings SQL Server does not allow remote aboutjav.com@gmail.com Microsoft ASP .NET 0 3rd May 2008 01:43 PM
moving from olde server (remote) to a new server (remote) =?Utf-8?B?b3B0c3RpY2ttYW4=?= Microsoft Frontpage 1 7th Jul 2005 02:43 AM
Frontpage 2003 publish web from remote iis 6.0 server to remote iis 6.0 server slow Lloyd Microsoft Frontpage 5 10th Feb 2005 03:37 PM
Re: Writing Remote Desktop Server or Remote Terminal Server Jose Solorzano Microsoft C# .NET 0 28th Dec 2004 06:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:47 AM.