簡體   English   中英

從服務器刪除文件:拒絕訪問路徑

[英]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的信息


似乎需要“ Modify權限才能刪除文件 嘗試授予NetworkService Modify權限。

我也有這個問題。 當我以這種方式應用代碼時,我沒有遇到任何權限請求。

    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