Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Create website programmatically iis 6

Posted on 2006-04-07
9
Medium Priority
?
750 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:Darth_helge
  • 6
  • 2
8 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 16399620

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("ServerBinding").SpawnInstance_()
colBindings(0).IP = SERVER_IP
colBindings(0).Port = "80"
colBindings(0).Hostname = "www.test.com"

Set objProvider = objLocator.ConnectServer("<Server Name>", "root/MicrosoftIISv2")
Set objService = objProvider.Get("IIsWebService='W3SVC'")

strSiteObjectPath = objService.CreateNewSite("Site Description / Server Comment", colBindings, "C:\Path\To\Site")

' 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("WbemScripting.SWbemObjectPath")
objPath.Path = strSiteObjectPath
strSitePath = objPath.Keys.Item("")

' Re-connect to the site and set the properties

Set objSite = objProvider.Get("IIsWebServerSetting='" & strSitePath & "'")
Set objVirtualDirectory = objProvider.Get("IIsWebVirtualDirSetting='" & strSitePath & "/ROOT'")

' Application Pool Creation

Set objAppPools = GetObject("IIS://<Server Name>/W3SVC/AppPools")
Set objAppPool = objAppPools.Create("IIsApplicationPool", "<App Pool Name>")
Set objAppPool = Nothing
Set objAppPools = Nothing

' Assign the Pool to the Site

objVirtualDirectory.AppFriendlyName = strServerName
objVirtualDirectory.AppPoolID = strServerName
objVirtualDirectory.SetInfo

' 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_Name
' 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
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 16399628

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.
0
 
LVL 5

Author Comment

by:Darth_helge
ID: 16399646
thank you but how do you choose which asp.net version to use? i can't see that in your code
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 71

Expert Comment

by:Chris Dent
ID: 16399756

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
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 16401053

Okay changing between the two different ASP.NET versions is pretty easy. You basically have to alter all the ScriptMaps it has in place, the application configuration in effect. The disadvantage is you have to check the version numbers that are being used.

This shows how you could switch from one to the other:

objSite = GetObject("IIS://<Server Name>/" & strSitePath)

' Change from 2.0 to 1.1

arrScriptMaps = objSite.ScriptMaps
For i = 0 to UBound(arrScriptMaps)
      If InStr(arrScriptMaps(i), "2.0.50727") Then
            arrScriptMaps(i) = Replace(arrScriptMaps(i), "2.0.50727", "1.1.4322")
      End If
Next

objSite.ScriptMaps = arrScriptMaps
objSite.SetInfo

' Change from 1.1 to 2.0

For i = 0 to UBound(arrScriptMaps)
      If InStr(arrScriptMaps(i), "1.1.4322") Then
            arrScriptMaps(i) = Replace(arrScriptMaps(i), "1.1.4322", "2.0.50727")
      End If
Next

objSite.ScriptMaps = arrScriptMaps
objSite.SetInfo

Chris
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 16401067

Oh and changing the entries in that array does make the change visible in the GUI, so it's nice and accessible afterwards.

Chris
0
 
LVL 5

Author Comment

by:Darth_helge
ID: 16406562
thanks Chris-Dent. I will try this probably on Monday :=)
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 16406606

Great, let me know how you get on :)

Chris
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I came across an interesting issue that had me pulling my hair out.  I was troubleshooting a new internal web site which uses integrated security instead of anonymous.  When browsing the site from my laptop, I was able to access it with no iss…
Lync server 2013 or Skype for business Backup Service Error ID 4049 – After File Share Migration
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question