473,473 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to programatically test file permissions

Hello,
In one of my asp.net applications I test the existence of a file, like so:

File.Exists(Server.MapPath("/path/file.jpg")));

This was failing, even though the path returned by Server.MapPath was
clearly present. After some debugging, I discovered that the the asp.net
account didn't have permission to execute File.Exists. Apparently
File.Exists simply returns "false" instead of throwing an exception if
it doesn't have the permissions it needs. This is pretty unintuitive.

Anyway, I would like to add an assert method that ensures I have the
proper permissions so that this does not happen again. How might I go
about doing that?

TIA,
Gabe
Sep 27 '06 #1
4 5843
On 27/09/2006 in message <OG**************@TK2MSFTNGP05.phx.gblGabe
Moothart wrote:
>Anyway, I would like to add an assert method that ensures I have the
proper permissions so that this does not happen again. How might I go
about doing that?
There's a very useful UserFileAccessRights class on CodeProject:
http://www.codeproject.com/useritems...cessRights.asp

Might that help?

--
Jeff Gaines
Sep 27 '06 #2
Jeff Gaines wrote:
There's a very useful UserFileAccessRights class on CodeProject:
http://www.codeproject.com/useritems...cessRights.asp

Might that help?
Yep, that's what I was looking for. Thanks!

Gabe
Sep 27 '06 #3
Some remarks inline.

Willy.

"Gabe Moothart" <ga**@imaginesystems.netwrote in message
news:OG**************@TK2MSFTNGP05.phx.gbl...
| Hello,
| In one of my asp.net applications I test the existence of a file, like so:
|
| File.Exists(Server.MapPath("/path/file.jpg")));
|
| This was failing, even though the path returned by Server.MapPath was
| clearly present.

Right, from a human's perspective the file is present, but from a security
perspective she is not. If the callers identity has no rights to read the
file attributes (this is what Exists does), it should return "false", that
is, for you (the caller) the file does not exist.

After some debugging, I discovered that the the asp.net
| account didn't have permission to execute File.Exists.
No, the account can perfectly execute File.Exists method, the caller is
simply missing the privilege required to inspect the file existense.

That's why File.Exists has little or no value, a true value returned doesn't
imply that you can access the file, a false return doesn't mean that the
file isn't present.
Willy.
Sep 28 '06 #4

"Gabe Moothart" <ga**@imaginesystems.netwrote in message
news:eo**************@TK2MSFTNGP06.phx.gbl...
| Jeff Gaines wrote:
| There's a very useful UserFileAccessRights class on CodeProject:
| http://www.codeproject.com/useritems...cessRights.asp
| >
| Might that help?
|
| Yep, that's what I was looking for. Thanks!
|
| Gabe

Note that calling these methods are expensive, you should only call them
when a File Open request has thrown.

Willy.

Sep 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rahul Apte | last post by:
How do I programmatically check whether ASP and Server Side Includes sub-components of the World Wide Web service are installed on a Windows 2003 Box? I want to do these checks as pre-install...
1
by: Mullin Yu | last post by:
I want to know can I add printer programatically? E.g. I want to create a File Printer to a specify local port, say, C:\test\test.prn with the name as FilePrinter Can I do so? Thanks! ...
0
by: Carlitos | last post by:
Hi there, I do not have much experience nor knowledge about security in ASP.NET nor Windows, so I apologize if I sound naive in this question. I developed a web application and a DLL that the...
4
by: vickaiser1 | last post by:
I am creating a setup project for an application and need to edit the Metabase.xml file during setup. Does anyone know of a way to stop and then restart services programatically before and after I...
4
by: carson | last post by:
I have written two windows services: - service A does some crunching of local data files and uploads them to a central processing computer via http. - service B monitors a manifest file on a...
5
by: Tim Mackey | last post by:
hi, i have put my web.sitemap in /App_Data so i can edit it programatically via a web admin page, inheriting the modify permissions from the App_Data folder etc. i was hoping the provider would...
1
by: jweiss | last post by:
I am trying to run cmd.exe so that I can ftp a file to a remote server. I've been doing this for a long time, but something broke. I did some windows updates last week?? I am getting a...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
I need to programatically upload a text file to a web server using the HTTPWebRequest object within .Net 2.0. So far, I have determined that: - I need a HTTP content-type of...
11
by: Mark B | last post by:
I want to display a pre-designed graphical 'performance badge' on certain webpages (round, about 2cm diameter) next to a salesperson's details. I have a function,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.