Delete file from server: Access to the path is denied

asp.netiis-7.5Security

I call this function from with my code-behind:
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.

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.

See here the settings I have on my Windows server on folder wwwroot:

SYSTEM: Full Control
NETWORK SERVICE: Read + Write + Read & Execute + List folder contents
IIS_IUSRS: Read + Write

As was suggested by other posts I've been reading I tried adding other user groups, but I have no ASPNET service/group on my server.

When logged in as administrator (Forms authentication) I can click a button to recreate the sitemap_index.xml and sitemaps.xml
Users should be able to delete and add images to the wwwroot\images\uploads folder

Which group should I give what permissions to allow the above to be possible AND secure?

Best Answer

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.... The name of the user that the pool is using is listed next to 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


It looks like Modify permissions are required to delete files. Try granting NetworkService Modify permissions.