Getting access denied while trying to create iis application from code

不想你离开。 提交于 2019-12-12 06:15:12

问题


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)).

回答1:


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.



来源:https://stackoverflow.com/questions/15553962/getting-access-denied-while-trying-to-create-iis-application-from-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!