2012-04-21 24 views
8

我刚刚在Windows XP上安装了IIS。访问路径'c: inetpub wwwroot myapp App_Data'被拒绝

当我试图执行一个应用程序,我得到一个错误:

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

我已经做这个尝试光栅权限:

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.

但错误依然存在。

这是否与我的代码有关?

我该如何解决这个问题?

编辑

我已经解决了我的开发机器上的问题,但我仍然得到我的Web服务器上的错误。

谢谢。

+0

用我的开发计算机上的文件只有一个,当我上载网上TI我的服务器,同样的事情也发生了。 – Smith 2012-04-21 07:16:42

+0

请问为什么要投票? – Smith 2012-10-27 23:25:39

回答

8

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

编号:
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?

如果不解决您的问题,然后检查你的XML文件是否没有被另一个线程打开使用这些配置文件..和提供一些更多细节如果仍然存在。

+0

你好,你能帮我看看新的错误吗?我得到了同样的错误在web服务器 – Smith 2012-04-23 07:01:51

1

您确定要添加正确的用户吗?您是否检查过为应用程序应用程序池设置哪个用户?

如果出于某种原因无法读取文件,也会发生此错误;如该文件被锁定或被另一个应用程序使用。由于这是一个ASP.NET Web应用程序,因此您需要确保没有执行任何要求文件被锁定的操作;除非您可以保证一次只在您的网页上拥有一位用户。

你可以发表你如何访问文件的例子吗?它是什么类型的文件?代码片段将帮助您获得更准确的答案。

4

考虑,如果你的文件是只读的,那么多余的参数可以与FileStream

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

帮助我有一个类似的情况。我正在使用TFS进行源代码控制。我发现,当它被检入时,它使得这些文件只读。这导致了我的服务中的上述错误,它打开它们的读/写。一旦我检查了他们的编辑。一切都很好。我正在考虑尝试在服务中只读打开它们。我认为一旦他们发布到生产服务器,这不是问题。只在开发环境中。我看到了使用实体框架的服务的类似问题。如果签入.svc文件,则无法通过EF对数据库执行更新。

+1

一个原因以及很多不使用TFS ... – 2014-01-19 19:07:24

0

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

1

我试图添加所有权限的ASP.net v4.0,添加NETWORK SERVICE用户,但没有任何帮助。 最后,在App_Data文件夹中添加了DefaultAppPool用户的MODIFY权限,问题解决了。

+0

这也为我工作。一个新的服务器和我的部署软件包甚至没有创建一个app_data文件夹。我创建了它,然后将修改权添加到DefaultAppPool – Luke 2015-11-14 00:43:48

0

请运行Visual Studio具有管理员privilege..This问题解决了我..

访问路径被拒绝C:\的Inetpub \ wwwroot的 被拒绝表示该自助服务网站可以不能访问安装它的服务器上的特定文件夹。 这可能是因为该位置不存在,或者因为身份验证用户没有应用写入此位置的任何权限。

0

另一个原因可能是因为您正在尝试写入的文件路径是空的,这就是为什么它找不到它。这是发生此错误的另一个原因。

2

对于Windows服务器上的运行IIS:

默认情况下,IIS的用户不必为wwwroot文件夹的写权限。这可以通过为wwwroot授予对IIS_IUSRS用户的完全权限来解决。

  1. 打开File Explorer并转到C:/inetpub/
  2. 右键单击wwwroot文件,然后单击“属性”
  3. 转到安全选项卡,然后单击“编辑...”编辑权限
  4. 查找和选择IIS用户。在我的情况下,它被称为IIS_IUSRS ([server name]\IIS_IUSRS)
  5. 为所有权限选择“允许”复选框。