Access to the path ‘c:inetpubwwwrootmyappApp_Data’ is denied

I just installed IIS on Windows XP.

When I try to execute an app, I get an error:

Access to the path ‘c:inetpubwwwrootmyappApp_Data’ is denied.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the
path ‘c:inetpubwwwrootmyappApp_Data’ is denied.

ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request
identity. ASP.NET has a base process identity (typically
{MACHINE}ASPNET on IIS 5 or Network Service on IIS 6) that is used if
the application is not impersonating. If the application is
impersonating via , the identity will be
the anonymous user (typically IUSR_MACHINENAME) or the authenticated
request user.

To grant ASP.NET access to a file, right-click the file in Explorer,
choose “Properties” and select the Security tab. Click “Add” to add
the appropriate user or group. Highlight the ASP.NET account, and
check the boxes for the desired access.

Source Error:

Line 70: Protected Sub cmbSettingFiles_SelectedIndexChanged(ByVal
sender As Object, ByVal e As System.EventArgs) Handles
cmbSettingFiles.SelectedIndexChanged
Line 71: Dim doc As XmlDocument = New XmlDocument()
Line 72: doc.Load(Path.Combine(basePath, cmbSettingFiles.SelectedValue))
Line 74: Dim settingsNode As XmlNode = doc.SelectSingleNode(“/settings”)

Source File: C:myappinstallinstall.aspx.vb Line: 72

I have tried grating permission by doing this:

To grant ASP.NET access to a file, right-click the file in Explorer,
choose “Properties” and select the Security tab. Click “Add” to add
the appropriate user or group. Highlight the ASP.NET account, and
check the boxes for the desired access.

But the error persists.

Does this have anything to do with my code?

How can I resolve this?

EDIT

I have solved the problem on my dev machine, but I am still getting the error on my web server.

Thanks.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If you’re getting this error, you’re probably trying to write to wwwroot. By default this is not allowed, for good reason.

Instead, consider storing your files somewhere besides wwwroot. If you just need to serve the files, store them in a folder outside of inetpub and use a virtual directory to make them visible to IIS.

Original answer:


For those running IIS on Windows Server:

By default, the IIS user does not have write permissions for the wwwroot folder. This can be solved by granting full permissions to the IIS_IUSRS user for wwwroot.

  1. Open File Explorer and go to C:/inetpub/
  2. Right click on wwwroot and click on “Properties”
  3. Go to the Security tab and click “Edit…” to edit permissions
  4. Find and select the IIS user. In my case, it was called IIS_IUSRS ([server name]IIS_IUSRS).
  5. Select the “Allow” checkbox for all permissions.

Method 2

Try to go to App_Data folder property and add ASPNET user with read
and write privileges

Ref:
How to assign correct permissions to App_Data folder of WebMail Pro ASP.NET
Permissions on APP_DATA Folder
ASP/ASP.NET Best way to handle write permissions?

If it does not solve your problem then check whether your XML files are not open by another thread using these configuration files.. and provide some more details if still persists.

Method 3

Consider if your file is read only, then the extra parameters may help with FileStream

using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))

Method 4

Are you sure you are adding the correct user? Have you checked to see which user is set for your applications app pool?

This error will also happen if it cannot read the file for some reason; such as the file is locked or used by another application. Since this is an ASP.NET web application you will want to make sure you are not performing any actions that would require the file to be locked; unless you can guarantee you will only have one user on your page at a time.

Can you post an example of how you access the file? What type of file is it? Code snippets will help you get a more exact answer.

Method 5

I had a similar situation. I am using TFS for source code control. What I found is that when it was checked in, it made the files readonly. This caused the above error in my service where it was opening them read/write. Once I checked them out for edit. Everything worked great. I am considering trying opening them readonly in the service. I think that once they get published to the production server, this is not an issue. Only in the development environment. I have seen similar issues with Services that use Entity Framework. If the .svc file is checked in, you can’t do updates to the database through EF.

Method 6

I tried to add ASP.net v4.0 with all permission, add NETWORK SERVICE user but nothing help.
At last, added the MODIFY right of DefaultAppPool user in App_Data folder, problem solved.

Method 7

Please Run Visual Studio with Administrator privilege..This Issue is solved for me..

Access to the path is denied C:inetpubwwwroot
is denied indicates that the Self Service web site can’t access a specific folder on the server where it is installed.
This could be either because the location doesn’t exist, or because the Authenticating User does not have any permissions applied to Write to this location.

Method 8

Try granting permission to the NETWORK SERVICE user.

Method 9

Another reason could be because the filepath is empty where you are trying to write which is why it can’t find it. just another reason why this error occurs.

Method 10

For me i had already created a folder with name excel in wwroot
D:working directoryOnlineExamwwwrootexcel
And i was trying to copy a file with name excel which was already existing as a folder name. the path which was required was
D:working directoryOnlineExamwwwrootexcelfinance.csv
so according i changed the code as below

string copyPath = Path.Combine(_webHostEnvironment.WebRootPath, "excel\finance");
                    questionExcelUpload.Upload.CopyTo(new FileStream(copyPath, FileMode.Create));

Basically check if a folder or a file with same name as your path exist already.

Method 11

I had the same problem and spent on it more time that I’d admit, especially since I was able to WRITE files to the same folder.

Only after testing a dozen other things I realized that my “path” variable only had the directory, and no filename! Bad, bad error message!

Before:

string path = Server.MapPath("~/App_Data/SpecialFolder");

After:

string path = Path.Combine(
      Server.MapPath("~/App_Data/SpecialFolder"),
      filename); //NOTE: will cause Access Denied if filename is missing or empty!

It’s possible the original error was also not due to denied access, but because the selected “filename” was an empty string.

Method 12

I finally found the answer for 2019. You need to add ‘IIS APPPOOLDefaultAppPool’ to the list of users that have security rights to the directory that is to be modified. Make sure they have full rights.

Method 13

I created copy of my inet folder, to make a duplicate of the site. It showed ‘access denied …/App_Data/viewstate/1/6/6/0 … ‘. On checking it showed that app_data folder is having IIS_IUSER addes but does not have modify or write acess checked. Just check those boxes and the instance begin to run.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x