Link to home
Start Free TrialLog in
Avatar of Ralf Klatt
Ralf KlattFlag for Germany

asked on

Is there a way to add subdomains to IIS 6.0 programatically?

Hi,

I'll have to add about 150 subdomains to a top level domain. Before starting to do this manually I'd like to know if there's a way to do it programatically -> passing values and parameters from a SQL Server Database.

I was looking for examples on the internet but have nothing found yet.

Does anyone have an idea? Or some links that explain how to do this programatically?

VB6, VBScript, VB.NET or C# hints or examples are very much appreciated!


Best regards,
Raisor
ASKER CERTIFIED SOLUTION
Avatar of karlossos
karlossos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ralf Klatt

ASKER

Hi,

Thanks a lot for the provided link that is also giving some source code to understand the basics of doing what I'm up to do!

Another thing that the provided link did was to give me an understanding on what I'll have to look for to make things even easier than to go with VB.NET:

Public Overrides Sub Install(ByVal stateSaver As _
System.Collections.IDictionary)
    Dim strVDir As String = Me.Context.Parameters.Item("VDir")
    Dim intServerNum As Integer = _
    Me.FindServerNum(Me.Context.Parameters.Item("Port"))
    Dim strObjectPath As String = "IIS://" & _
    System.Environment.MachineName & "/W3SVC/" & _
    intServerNum.ToString & "/ROOT/" & strVDir
    Dim IISVdir As Object

    ' Gets the IIS VDir Object.
    IISVdir = GetIISObject(strObjectPath)

    ' Set the AuthAnonymous property here.
    IISVdir.AuthAnonymous = False

    ' Uses SetInfo to save the settings to the Server.
    IISVdir.SetInfo()
End Sub

What I found, using the information you've provided was infact a C#.NET approach that I'll try to leverage:

public class SetupUtility{public SetupUtility(){}public int CreateWebSite(string webSiteName, string pathToRoot){return CreateWebSite(webSiteName, pathToRoot, false);}public int CreateWebSite(string webSiteName, string pathToRoot, bool createDir){DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");// Find unused ID value for new web siteint siteID = 1;foreach(DirectoryEntry e in root.Children){if(e.SchemaClassName == "IIsWebServer"){int ID = Convert.ToInt32(e.Name);if(ID >= siteID){siteID = ID+1;}}}// Create web siteDirectoryEntry site = (DirectoryEntry)root.Invoke("Create", "IIsWebServer", siteID);site.Invoke("Put", "ServerComment", webSiteName);site.Invoke("Put", "KeyType", "IIsWebServer");site.Invoke("Put", "ServerBindings", ":80:");site.Invoke("Put", "ServerState", 2);site.Invoke("Put", "FrontPageWeb", 1);site.Invoke("Put", "DefaultDoc", "Default.aspx");site.Invoke("Put", "SecureBindings", ":443:");site.Invoke("Put", "ServerAutoStart", 1);site.Invoke("Put", "ServerSize", 1);site.Invoke("SetInfo");// Create application virtual directoryDirectoryEntry siteVDir = site.Children.Add("Root", "IISWebVirtualDir");siteVDir.Properties["AppIsolated"][0] = 2;siteVDir.Properties["Path"][0] = pathToRoot;siteVDir.Properties["AccessFlags"][0] = 513;siteVDir.Properties["FrontPageWeb"][0] = 1;siteVDir.Properties["AppRoot"][0] = "LM/W3SVC/"+siteID+"/Root";siteVDir.Properties["AppFriendlyName"][0] = "Root";siteVDir.CommitChanges();site.CommitChanges();return siteID;}}

... as soon as I have a "working" solution I'll share the peace of code that does what I'm up to do!

Thanks a lot for your help, karlossos ...


Best regards,
Raisor
Hi,

Just an addon for anyone reading the C#.NET approach: I've found it at http://weblogs.asp.net/jezell/archive/2003/09/17/27869.aspx

... there are some useful diffs to the presented code there!


Best regards,
Raisor