1

I'm working on a web service installation. One of the things I need to do is creating a new virtual directory under the default web site. The problem is I need to set a different application pool for that virtual directory (please don't ask why...these are the requirements and nothing I can do about it).

In IIS6, since there is no difference between virtual directories and applications I have no problem doing so. In IIS7, it is not possible setting an application pool to a virtual directory so I need to create a new "application" and attach an application pool to it.

I couldn't find any reasonable example/tutorial for doing so in C#. I need some help please :-)

Thanks.

2 Answers 2

1

Found the answer somewhere out there. I'm using the same code for creating the virtual directory in IIS6 and the application on IIS7:

  DirectoryEntry defaultWebSite = GetWebSiteEntry(DEFAULT_WEB_SITE_NAME);
  DirectoryEntry defaultWebSiteRoot = new DirectoryEntry(defaultWebSite.Path + "/Root");

  //Create and setup new virtual directory
  DirectoryEntry virtualDirectory = defaultWebSiteRoot.Children.Add(applicationName, "IIsWebVirtualDir");

  virtualDirectory.Properties["Path"][0] = physicalPath;
  virtualDirectory.Properties["AppFriendlyName"][0] = applicationName;
  virtualDirectory.CommitChanges();

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

  object[] param = { 0, applicationPoolName, true };
  virtualDirectory.Invoke("AppCreate3", param);
Sign up to request clarification or add additional context in comments.

1 Comment

I'm having trouble finding GetWebSiteEntry. I have referenced System.Web in my class library, but can't find any sign of that method. Can you point me at some "using" or references I might need?
0

With C# you can try running some server side script that creates virtual directory.

Take a script similar to: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5adfcce1-030d-45b8-997c-bdbfa08ea459.mspx?mfr=true

And run it with 'Execute' command: http://www.codeproject.com/KB/cs/Execute_Command_in_CSharp.aspx

1 Comment

Mantas: Thank's for replying, I'm already familiar with these scripts (the IIS7 has the appcmd) but I need to write a c# code and besides, event using these scripts I still don't know how to create an application (virtual directory is OK).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.