简体   繁体   English

从服务器删除文件:拒绝访问路径

[英]Delete file from server: Access to the path is denied

I call this function from with my code-behind:我用我的代码隐藏调用这个 function:
DeleteFile(Server.MapPath("/") + "sitemap_index.xml") 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

I then get the error: Access to the path 'E:\zz\wwwroot\sitemap_index.xml' is denied.然后我收到错误:拒绝访问路径“E:\zz\wwwroot\sitemap_index.xml”。

In other sites of myself this logic works great, however on the current site it doesnt.在我自己的其他网站上,这种逻辑很有效,但在当前网站上却没有。 I checked the security settings on my windows server 2008 R2 Standard.我检查了我的 windows 服务器 2008 R2 Standard 上的安全设置。

See here the settings I have on my Windows server on folder wwwroot:在这里查看我在 Windows 服务器上的 wwwroot 文件夹中的设置:

SYSTEM: Full Control系统:完全控制
.NETWORK SERVICE: Read + Write + Read & Execute + List folder contents .NETWORK SERVICE:读取+写入+读取和执行+列出文件夹内容
IIS_IUSRS: Read + Write IIS_IUSRS:读+写

As was suggested by other posts I've been reading I tried adding other user groups, but I have no AS.NET service/group on my server.正如我一直在阅读的其他帖子所建议的那样,我尝试添加其他用户组,但我的服务器上没有 AS.NET 服务/组。

When logged in as administrator (Forms authentication) I can click a button to recreate the sitemap_index.xml and sitemaps.xml当以管理员身份登录时(表单身份验证),我可以单击一个按钮来重新创建 sitemap_index.xml 和 sitemaps.xml
Users should be able to delete and add images to the wwwroot\images\uploads folder用户应该能够在 wwwroot\images\uploads 文件夹中删除和添加图像

Which group should I give what permissions to allow the above to be possible AND secure?我应该向哪个组授予哪些权限才能使上述操作成为可能且安全?

Check the access for the Application Pool user. 检查应用程序池用户的访问权限。

Find the application pool that your site is using, right click on it and choose Advanced Settings... . 找到您的站点正在使用的应用程序池,右键单击它,然后选择“ Advanced Settings... The name of the user that the pool is using is listed next to Identity . Identity旁边列出了池正在使用的用户的名称。

Note that if the identity says "ApplicationPoolIdentity", you should check the access for the user IIS AppPool\\<Name of the app pool here> Info about ApplicationPoolIdentity 请注意,如果身份显示为“ ApplicationPoolIdentity”,则应检查用户IIS AppPool\\<Name of the app pool here>的访问权限IIS AppPool\\<Name of the app pool here> 有关ApplicationPoolIdentity的信息


It looks like Modify permissions are required to delete files . 似乎需要“ Modify权限才能删除文件 Try granting NetworkService Modify permissions. 尝试授予NetworkService Modify权限。

I had this problem too.我也有这个问题。 When I applied the codes in this way, I did not encounter any permission requests.当我以这种方式应用代码时,我没有遇到任何权限请求。

    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.

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