简体   繁体   中英

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.

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.

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.

考虑您的文件是否是只读的,那么额外的参数可能有助于FileStream

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

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.

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

尝试向 NETWORK SERVICE 用户授予权限。

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.

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.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM