[asp.net] Access to the path 'c:\inetpub\wwwroot\myapp\App_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:\inetpub\wwwroot\myapp\App_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:\inetpub\wwwroot\myapp\App_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:\myapp\install\install.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.

This question is related to asp.net iis access-denied

The answer is


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))

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.

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


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.


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.


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.


Try granting permission to the NETWORK SERVICE user.


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.


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

Access to the path is denied C:\inetpub\wwwroot 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.


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.


For me i had already created a folder with name excel in wwroot D:\working directory\OnlineExam\wwwroot\excel 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 directory\OnlineExam\wwwroot\excel\finance.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.


Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to iis

ASP.NET Core 1.0 on IIS error 502.5 CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default Publish to IIS, setting Environment Variable IIS Manager in Windows 10 The page cannot be displayed because an internal server error has occurred on server The service cannot accept control messages at this time NuGet: 'X' already has a dependency defined for 'Y' Changing project port number in Visual Studio 2013 System.Data.SqlClient.SqlException: Login failed for user "This operation requires IIS integrated pipeline mode."

Examples related to access-denied

pip install access denied on Windows Getting "java.nio.file.AccessDeniedException" when trying to write to a folder mysqldump Error 1045 Access denied despite correct passwords etc Hosting ASP.NET in IIS7 gives Access is denied? MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES) Access to the path 'c:\inetpub\wwwroot\myapp\App_Data' is denied Access restriction: Is not accessible due to restriction on required library ..\jre\lib\rt.jar IIS Express gives Access Denied error when debugging ASP.NET MVC Access to the path denied error in C# Unable to copy file - access to the path is denied