Hi Dave.
Thank you for posting.
As for the
=========
I want to make sure all files pulled from my server app (ASP.NET 2.0) come
from one of 3 directories -
=========
You mentioned, would you please provide some further description on it? So
far I'm still quite confused about the operation you're doing or your
ASP.NET application's code logic. Based on my understanding, as for a file,
if it is existing on the physical disk, we can access it through File class
which will contains full path info. However, when we've loaded file stream
into memory, they'll no longer contain disk file info...
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Signature
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi;
In my app the user can enter a file (an xml data file) that resides on the
server to be used as a datasource. For security reasons I don't want them
able to get any file on the computer (like the ones in c:\windows) but they
may need to get files I put in places like c:\employees\data.
So when they give me a filename (not stream, just the filename) - I want to
check it against c:\employees\data\ and make sure it is in that directory or
a subdirectory of that.

Signature
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
> Hi Dave.
>
[quoted text clipped - 31 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Steven Cheng[MSFT] - 29 May 2006 03:20 GMT
Thanks for your response Dave,
So I've got your point that you want to verify the existence of a certain
file(given the name) within several directories, correct? I suggest you
have a look at the Sytem.IO namespace's classes, and they are specific to
IO operations against physical directory and files. For example, the
Directory class and the File class contains many static methods to do some
generic IO operations.
#System.IO Namespace
http://msdn2.microsoft.com/en-us/library/system.io.aspx
BTW, when you try accessing UNC share, make sure your ASP.NET's current
security context (process identity or impersonated user) has the permission
to access the share directory.
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Signature
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
David Thielen - 01 Jun 2006 16:36 GMT
Ok, I've implemented this. If anyone else needs it it is at
http://www.davidthielen.info/programming/2006/06/is_directory_ac.html If you
see any problems (ie MFUs) in the code please comment on the blog so others
know too.

Signature
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
> Thanks for your response Dave,
>
[quoted text clipped - 31 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Steven Cheng[MSFT] - 02 Jun 2006 02:37 GMT
Thanks for your followup and share the solution with us.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Signature
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Ben Voigt - 29 May 2006 14:40 GMT
> Hi;
>
[quoted text clipped - 9 lines]
> or
> a subdirectory of that.
In this scenario, I don't think giving your users maximum flexibility is a
design goal. There's no reason they should be entering
\\?\C:\Windows\..\Employees\DaTa and expecting your website to recognize
that it's an authorized directory. Require them to use the canonical name.
Use a strong regex and be done with it. If they can't stop using the CAPS
LOCK key when they fill in your form, give them a client-side javascript to
help them get it right. Let the server be ultra-strict.
i.e. something like
@"c:\\(employees|managers|otherdatadir)\\data\\[-_A-Za-z0-9]{1,50}\.xml"
It's rather desirable to limit filenames to a bounded sequence of
alphanumeric characters as I've done, in order to prevent parent paths (..),
redirection symbols (< > >> |), NTFS hidden streams, and all manner of other
evil such as "c:\employees\data\I_AM_A_BUFFER_OVERFLOW_HAHAHA_<overwrite
your return address here>.xml".
>> Hi Dave.
>>
[quoted text clipped - 37 lines]
>> (This posting is provided "AS IS", with no warranties, and confers no
>> rights.)