Daniel Tranca
Daniel Tranca

Reputation: 1455

Getting access denied while trying to create iis application from code

I'm trying to create a application from a directory inside a IIS website. Basically what I'm trying to do is to reproduce this flow in code: right-click on a folder inside an IIS website and click to convert to application.

this is my code:

        DirectoryEntry appsRoot = new DirectoryEntry("IIS://localhost/w3svc/3/Root");

        //Create and setup new virtual directory
        DirectoryEntry virtualDirectory = appsRoot.Children.Add(tool.Id.ToString(), "IIsWebVirtualDir");

        virtualDirectory.Properties["Path"][0] = Path.Combine(AppConfig.ToolsFilePath, tool.Id.ToString());
        virtualDirectory.Properties["AppFriendlyName"][0] = tool.Name;
        virtualDirectory.CommitChanges();

        // IIS6 - it will create a virtual directory
        // IIS7 - it will create an application
        virtualDirectory.Invoke("AppCreate", 1);

The error I get is Access is denied.

Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

Upvotes: 0

Views: 877

Answers (1)

Phillip Schmidt
Phillip Schmidt

Reputation: 8818

You can either set up your application to run as a more privileged user, or you can give all of the necessary permissions to whatever user the application is currently running as. I'd suggest the latter. If you don't know how to do that let me know and I can add details.

Upvotes: 1

Related Questions