views:

284

answers:

1

I'm able to create a Virtual Directory in IIS7 using the Microsoft.Web.Administration dll pretty easily in the code shown below but I've been pulling my hair out trying to find out how to give "Network Service" write permissions to the Virtual Directory once it's been created. Can anyone point me in the right direction?

Private Sub CreateVirDir(ByVal WebSite As String, ByVal AppPath As String, ByVal VirPath As String, ByVal DirPath As String)
    Dim sm As New Microsoft.Web.Administration.ServerManager()
    Dim cpapp As Microsoft.Web.Administration.Application = sm.Sites(WebSite).Applications(AppPath)
    cpapp.VirtualDirectories.Add(VirPath, DirPath)
    sm.CommitChanges()
End Sub
A: 

Assuming this is NTFS write permissions, you don't apply write permissions on the virtual directory itself. You would need to apply this permission on the folder that the virtual directory points to.

You can use the following namespaces to programmatically set NTFS permissions:

System.IO
System.Security.AccessControl

The following link has example code that demonstrates how to manipulate NTFS ACL's:

FileSecurity Class (MSDN Library)

Kev

related questions