473,785 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ 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(Ser ver.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 5873
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 UserFileAccessR ights 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 UserFileAccessR ights 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**@imaginesy stems.netwrote in message
news:OG******** ******@TK2MSFTN GP05.phx.gbl...
| Hello,
| In one of my asp.net applications I test the existence of a file, like so:
|
| File.Exists(Ser ver.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**@imaginesy stems.netwrote in message
news:eo******** ******@TK2MSFTN GP06.phx.gbl...
| Jeff Gaines wrote:
| There's a very useful UserFileAccessR ights 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
1940
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 checks for a software. Thanks in advance. - Rahul A.
1
2853
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! Regards,
0
1557
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 web application uses. This DLL moves files from the web server to a shared folder in a different server in the intranet. It seems ASPNET user account can move some files but not all types of files because it does not have enough permissions to...
4
2699
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 edit this file? Vic
4
21756
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 webserver to see if service A needs to be updated. What service B does if it sees their is an update for service A is to download a new copy of the service A executable, stop service A, replace the executable with the new copy, and start service B...
5
15074
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 simply persist any changes i made, but it doesn't happen. e.g. selected.ParentNode.ChildNodes.Remove(selected); throws a NotSupportedException "Collection is read-only"
1
3974
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 'permission denied' error at this line 48... 48 Call oScript.Run ("C:\inetpub\wwwroot\test\cmd.exe /c " & strCMD & " > " & strTempFile, 0, True) I am stumbling with permissions here. Here is where my cmd.exe lives (i copied it from system32)...
3
4232
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 "multipart/form-data". - I need to use the ContentType.Boundary property. That is about as far as I have gotten.
11
5389
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, fGetPerformanceGrade(SalesPersonID as Long) as String to retrieve that salesperson's grade (e.g. A+, A, A-, B+, B... D). Also one other function, fGetMonthlySales(SalesPersonID as Long) as String to get their sales figure, e.g. "$87K". I want web visitors to be able to click...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8978
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.