[英]Delete file from server: Access to the path is denied
我用我的代码隐藏调用这个 function:
DeleteFile(Server.MapPath("/") + "sitemap_index.xml")
Public Shared Function DeleteFile(ByVal filename As String) As Boolean
'deletes file from server
Dim bResult As Boolean = False
Try
If File.Exists(filename) Then
'delete file
File.Delete(filename)
bResult = True
Else
bResult = True
End If
Catch ex As Exception
End Try
Return bResult
End Function
然后我收到错误:拒绝访问路径“E:\zz\wwwroot\sitemap_index.xml”。
在我自己的其他网站上,这种逻辑很有效,但在当前网站上却没有。 我检查了我的 windows 服务器 2008 R2 Standard 上的安全设置。
在这里查看我在 Windows 服务器上的 wwwroot 文件夹中的设置:
系统:完全控制
.NETWORK SERVICE:读取+写入+读取和执行+列出文件夹内容
IIS_IUSRS:读+写
正如我一直在阅读的其他帖子所建议的那样,我尝试添加其他用户组,但我的服务器上没有 AS.NET 服务/组。
当以管理员身份登录时(表单身份验证),我可以单击一个按钮来重新创建 sitemap_index.xml 和 sitemaps.xml
用户应该能够在 wwwroot\images\uploads 文件夹中删除和添加图像
我应该向哪个组授予哪些权限才能使上述操作成为可能且安全?
检查应用程序池用户的访问权限。
找到您的站点正在使用的应用程序池,右键单击它,然后选择“ Advanced Settings...
。 Identity
旁边列出了池正在使用的用户的名称。
请注意,如果身份显示为“ ApplicationPoolIdentity”,则应检查用户IIS AppPool\\<Name of the app pool here>
的访问权限IIS AppPool\\<Name of the app pool here>
有关ApplicationPoolIdentity的信息
我也有这个问题。 当我以这种方式应用代码时,我没有遇到任何权限请求。
public void DeleteDirectory(string target_dir)
{
string[] files = Directory.GetFiles(target_dir);
string[] dirs = Directory.GetDirectories(target_dir);
foreach (string file in files)
{
System.IO.File.SetAttributes(file, FileAttributes.Normal);
System.IO.File.Delete(file);
}
foreach (string dir in dirs)
{
DeleteDirectory(dir);
}
Directory.Delete(target_dir, false);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.