Darth_helge
asked on
Create website programmatically iis 6
how do i create a website programmatically in iis 6?
i am using vs 2005
is there any easy way to do this?
Here is something i want to configure on creation
website folder
description
application pool
asp.net version
host header
i am using vs 2005
is there any easy way to do this?
Here is something i want to configure on creation
website folder
description
application pool
asp.net version
host header
This bit:
You can do all of that using the ADSI interface.
Should have said:
You can do all of that using the ADSI and WMI interfaces.
ASKER
thank you but how do you choose which asp.net version to use? i can't see that in your code
Oh sorry, forgot to mention that. They only brought that in with ASP.Net 2.0, I just haven't had a chance to look where it's stored yet. I'll have a dig around the metabase this afternoon, doesn't matter if I break it on my machine ;)
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh and changing the entries in that array does make the change visible in the GUI, so it's nice and accessible afterwards.
Chris
ASKER
thanks Chris-Dent. I will try this probably on Monday :=)
Great, let me know how you get on :)
Chris
You can do all of that using the ADSI interface. There is only one slight problem with me describing it for you though, I don't do anything with VB, only VBScript.
Still, much of it is translatable sort of, I have some vague notes on C# versions of some of this somewhere, but that's probably not much help either.
That said... In some sort of order...
' Bindings (Host Header) get loaded into a collection initially, they're easy enough to alter later on but we
' need at least one to setup the site:
colBindings = Array(0)
Set colBindings(0) = objProvider.Get("ServerBin
colBindings(0).IP = SERVER_IP
colBindings(0).Port = "80"
colBindings(0).Hostname = "www.test.com"
Set objProvider = objLocator.ConnectServer("
Set objService = objProvider.Get("IIsWebSer
strSiteObjectPath = objService.CreateNewSite("
' We're going to get the Metabase Path for the site from the string returned by the CreateNewSite method.
' Required to play around with some of it's settings.
Set objPath = CreateObject("WbemScriptin
objPath.Path = strSiteObjectPath
strSitePath = objPath.Keys.Item("")
' Re-connect to the site and set the properties
Set objSite = objProvider.Get("IIsWebSer
Set objVirtualDirectory = objProvider.Get("IIsWebVir
' Application Pool Creation
Set objAppPools = GetObject("IIS://<Server Name>/W3SVC/AppPools")
Set objAppPool = objAppPools.Create("IIsApp
Set objAppPool = Nothing
Set objAppPools = Nothing
' Assign the Pool to the Site
objVirtualDirectory.AppFri
objVirtualDirectory.AppPoo
objVirtualDirectory.SetInf
' If you need to rewrite Bindings they can be treated as an Array but it has to be done via ADSI not
' WMI / WBEM
objSite = GetObject("IIS://<Server Name>/" & strSitePath)
arrBindings = objSite.ServerBindings
' You now have an array of lines like this:
' SERVER_IP:HTTP_PORT:Domain
' i.e. 192.168.1.1:80:www.test2.com
' If you want to add more just add them to the array and load it back in:
objSite.ServerBindings = arrBindings
objSite.SetInfo