I need to programatically create an IIS website. Can anybody show me the code to do this?
+3
A:
This will work for IIS 6.0 and later, it's written in VB.Net (which, this is small enough to easily to convert to C# if needed). I also didn't write this, I found it here (I did compile it though to make sure it would build): http://www.gafvert.info/notes/VBNET-Create-Website-IIS6.htm
Imports System.DirectoryServices
Imports System
Public Class IISAdmin
Public Shared Function CreateWebsite(webserver As String, serverComment As String, serverBindings As String, homeDirectory As String) As Integer
Dim w3svc As DirectoryEntry
w3svc = New DirectoryEntry("IIS://localhost/w3svc")
'Create a website object array
Dim newsite() As Object
newsite = New Object(){serverComment, new Object(){serverBindings}, homeDirectory}
'invoke IIsWebService.CreateNewSite
Dim websiteId As Object
websiteId = w3svc.Invoke("CreateNewSite", newsite)
Return websiteId
End Function
Public Shared Sub Main(args As String())
Dim a As Integer
a = CreateWebsite("localhost", "Testing.com", ":80:Testing.com", "C:\\inetpub\\wwwroot")
Console.WriteLine("Created website with ID: " & a)
End Sub
End Class
John
2009-04-20 16:37:41
You beat me to it :)
Kirtan
2009-04-20 16:38:44
I also suspect this will need to be run from the web-server because it points to IIS://localhost Not sure how it would work remotely, it would depend on your security setup.
John
2009-04-20 16:38:56
@ Kirtan. Hehe. :) I usually don't post here, was a fluke, I saw the question and thought, I know I've seen that done somewhere, hehe.
John
2009-04-20 16:39:32
C# equivalent to the abovehttp://www.gafvert.info/notes/CreateWebSiteIIS6.htm
MattH
2009-12-03 16:34:40
A:
The best place for information on IIS 7, that I found so far is here
CheGueVerra
2009-04-20 16:41:54