Access to path denied error.

K

Kevin Quigley

Hi,

I have a configuration file which stores sql server connection details
and some other application data, stored in a directory. When I try to
access this file in my code, I get the following error....

Access to the path "D:\WEBSERVER\WeeklyReport\Config\Accounts.Config" is
denied.

I have gave the ASPNET user full permissions on the directory and
impersonate is set to false.

Any help would be greatfully appreciated.

Thanks.
 
C

Chris Jackson

Special rules apply to configuration files, which prevent them from being
read. This is to ensure that somebody can't type in the URL of your config
file and read the connection strings from it. Instead of creating your own
and working around access issues, why not just use web.config, which is
specifically crafted for ASP.NET and has support in the class library? Then,
you can access values as:

System.Configuration.ConfigurationSettings.AppSettings["settingName"]
 
K

Kevin Quigley

Hi,

Thanks for the reply Chris, I do usually use the web.config file for
connection values, but this problem has been annoying me.

After having this problem I then created a simple web app to read a file
from a folder within the web app.....

string fileName = HttpContext.Current.Server.MapPath("test/test.txt");
StreamReader sr = File.OpenText(fileName);

I created a folder 'test' and gave the aspnet user full access
permissions. When I ran the code I got the 'access to the path ..... is
denied' error page. I then gave read permissions to the 'Everyone' group
and it worked okay.

Again, for this app, impersonate is set to false.

Any ideas how this is happening?

Thanks again for your help.

Kevin.
 
H

Harry Simpson

TRY:
string fileName = HttpContext.Current.Server.MapPath("test.txt");
StreamReader sr = File.OpenText(fileName);

This should work.

Harry Simpson
 
K

Kevin Quigley

Hi,

Thanks for the replies and apologies for not responding for so long,
I've been off for the past two weeks.

The problem was that the account the asp.net applications were running
under was not the ASPNET user. Instead it was a IWAM_ account. The
problem was then easily resolved by giving this IWAM_ account the
required permissions.

To view the account the application is running under you can use the
following :

System.Security.Principal.WindowsIdentity.GetCurrent().Name

Thanks again.

Kevin.
 

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

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top