Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to connect and create virtual directory in c#. While trying to create virtual directory i am getting access denied issue.

I have given permission to IIS USERS . Added
computername\IIS_IUSRS
& everyone too.

Exception occuring at
DirectoryEntry folderRoot = _iisServer.Children.Find("Root",VirDirSchemaName);


What I have tried:

/// <summary>
///     Create a virtual directory
/// </summary>
/// <param name="nameDirectory">Name of the new virtual directory</param>
/// <param name="realPath">Path of the directory</param>
public void CreateVirtualDirectory(string nameDirectory,string realPath)
{
    DirectoryEntry folderRoot = _iisServer.Children.Find("Root",VirDirSchemaName);

    try
    {
        DirectoryEntry newVirDir = folderRoot.Children.Add(nameDirectory,VirDirSchemaName);
        // Set Properties
        newVirDir.Properties["AccessRead"].Add(true);
        newVirDir.Properties["Path"].Add(realPath);
        // Create a Application
        newVirDir.Invoke("AppCreate",true);
        // Save Changes
        newVirDir.CommitChanges();
        folderRoot.CommitChanges();
        _iisServer.CommitChanges();
    }
    catch (Exception e)
    {
        throw new Exception("Virtual Directory " + nameDirectory + " Already Exists",e);
    }
}
Posted
Updated 29-Aug-19 0:31am

1 solution

This question already have some solutions available just Check these links

Creating FTP and Web IIS virtual directories[^]

Creating Virtual directory in IIS with c# - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900