IIS - Virtual Directory Creation - Asked By Nandini Parimi on 15-Feb-12 03:11 PM

Hi,
I am trying to create a virtual directory using C#.
Please find below the error i am getting :


[COMException (0x80005000): Exception from HRESULT: 0x80005000]

System.DirectoryServices.Interop.IAdsContainer.Create(String className, String relativeName) +0

System.DirectoryServices.DirectoryEntries.Add(String name, String schemaClassName) +38

website.AssociateMasterAccount_updated.ProcessRequest(HttpContext context) in R:\Source\ProjectsNandini\website_now\AssociateMasterAccount_updated.ashx.cs:86

System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100

System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

</pre></code>

I have installed all IIS components, Given IIS_IUSRS permissions also.

[)ia6l0 iii replied to Nandini Parimi on 15-Feb-12 10:27 PM
You are creating virtual directory through code? Does the code run in context of a user who has permission to create vd?
You should impersonate with an account that has sufficient priveleges to create/modify IIS.



Somesh Yadav replied to Nandini Parimi on 16-Feb-12 12:17 AM
Hi,

Hmmm looks like the connection string,

Best approach to do this kinda of stuff is use the softerra LDAP browser and try to connect ur LDAP system with the same DN and see how it goes...???

Hope it helps you.
Nandini Parimi replied to Nandini Parimi on 16-Feb-12 09:46 AM
System.DirectoryServices.DirectoryEntry site = new DirectoryEntry(@"C:\");


DirectoryEntries vdirs = site.Children;



DirectoryEntry newVDir = vdirs.Add("TestFolder/TestVir1", "IISWebVirtualDir");



Console.WriteLine(newVDir.Path);

newVDir.Properties[


"Path"][0] = "C:\\marathon-data\\00000058\\";

newVDir.Properties[


"AccessScript"][0] = true;

newVDir.Properties[

"AppFriendlyName"][0] = "TestVir";

newVDir.Properties[

"AppIsolated"][0] = "1";

newVDir.Properties[

"AppRoot"][0] = "/LM" + metabasePath.Substring(metabasePath.IndexOf("/", ("IIS://".Length)));


Console.WriteLine(newVDir.Properties["AppRoot"][0]);


newVDir.CommitChanges();




This is my code.I have 2 websites in IIS.One is Default , the other is named as TestSite.TestSite is located in c:\TestFolder.
And i would like to create a virtual directory for this site.
I am not able to understand how to point to this particular location..

Please Please help...