PDA

View Full Version : IIS Host Header Value



Jsowen
05-12-2004, 10:15 AM
Hi, I am trying to setup an Installscript MSI project to create multiple web sites hosted on a single machine.

I have created the web sites ok, but I can't find how to set or add a host header value for the web site.

Can anyone help... please..!

Thanks

rosario
06-28-2004, 08:49 AM
I too would be interested in that!

Jsowen
06-28-2004, 09:00 AM
Hi,

To set the host header you need to set the IIS Web site port number to port:header_name e.g. 80:header.co.uk

Hope this helps..

Cheers

Jo

Baggies
09-14-2004, 05:51 AM
Hi

Anyway that this could be done dynamically from user input?

Please note - I need to include this in an Installscript project which cannot be converted to an Installscript/MSI project.

Any help much appreciated.

Perucho
09-14-2004, 12:30 PM
Maybe if you create the IIS WebSite using InstallScript instead of using the IIS IDE tool, and then you can set the port number as well.

check out this post: http://community.installshield.com/showthread.php?s=&threadid=137227

check out these links/urls:
http://www.winnetmag.com/Articles/Print.cfm?ArticleID=21550
http://msmvps.com/bernard/archive/2004/07/29/10855.aspx
http://www.iisfaq.com
http://www.iisadministrator.com
http://support.microsoft.com/?id=324287
http://support.microsoft.com/?id=308163

You could use the WSH script MkW3Site.vbs to create IIS websites or you can try porting the vbs script to InstallScript code.

download the code: http://www.winnetmag.com/Files/11/21550/21550.zip

Baggies
09-28-2004, 05:46 AM
Many thanks for your help.

I indeed used the MKW3Site.vbs scripts and ported them to Installscript.

We now have the flexibility to do everything we now need it too in regards to creating & upgradeing websites & webservers (except for setting Execute Permissions for a webserver which just doesn't want to work :confused: )

Again, thanks for the help and info.

chrisgwilliams
01-20-2005, 09:02 AM
any chance of you posting the ported installscript?

You would make my life much easier!!

Baggies
01-20-2005, 11:11 AM
Chris, here's all the code I've got regarding using ADSI to create websites/virtual dirs/ etc.

Please note, these are all written custom to our needs, therefore certain items in these functions will not be necessary for yourself and no doubt some that you require will be missing - but they cover a lot and will give you a start.

Hope they are of use anyway. These have been used without issue in a number of our releases now so do the job (for us anyway). It's a shame that Installshield's advertised IIS support is sooo restrictive and frankly unusable.

Note - they all rely on knowing the IIS site ID number; if you don't already know it (and when we're deploying, how often do we?) then call GetNextWebSiteID passing the name of the site you want to create - it will then return either the next available site number or the site number of it if it (the named site) already exists (it will also return a bool value indicating whether the site already exists or not - this is used in the call to CreateVirtualDirectory).

GetWebSiteRoot is handy if you want to upgrade a current website - you can use this to get the installation path & don't have to rely on the user pointing your files to the wrong directory and screwing the site & upgrade up!

The execute permissions bit works in here too (unlike stated in my previous post).

I've left in commented out messageboxes which I used when debugging these when I first wrote them - just in case they come in handy for you.

I apologise however for the forum message formatting removing my indenting(!!) and the pants use of a try-catch in GetNextWebSiteID.


//////////////////////////////////////////////////////////////////////////
//various webservice functions
//////////////////////////////////////////////////////////////////////////
prototype NUMBER CreateWebSite(number, string, string, string, string);
prototype NUMBER GetNextWebSiteID(string, BYREF number, BYREF BOOL);
prototype NUMBER CreateVirtualDirectory(number, string, BOOL);
prototype NUMBER StartWebService(number);
prototype NUMBER GetWebSiteRoot(NUMBER, BYREF STRING);

function GetWebSiteRoot(nvSiteID, srSiteRoot)
OBJECT IISOBJRoot, objSite;
NUMBER nvReturn, nSiteID;
STRING szMsg, szSiteID;
STRING szSiteRoot;
begin
nvReturn = 0;
NumToStr(szSiteID, nvSiteID);
//we have the site id, so lets get the address for it
try
set objSite = CoGetObject("IIS://LocalHost/W3SVC/"+szSiteID, "");
if (IsObject(objSite)) then
//MessageBox("Success getting objSite object\nWebRoot Name: " +objSite.ServerComment, INFORMATION);
//is this website already installed? if so, use it if the user has passed a value
set IISOBJRoot = CoGetObject(objSite.ADSPath + "/Root", "");
szSiteRoot = IISOBJRoot.Path;
//MessageBox("Site root: " + szSiteRoot, INFORMATION);
nvReturn = 0;
endif;
catch
MessageBox("Failed getting objW3SVC object - siteid: " +szSiteID, INFORMATION);
nvReturn = 1;
endcatch;

srSiteRoot = szSiteRoot;

if (IsObject(IISOBJRoot)) then
set IISOBJRoot = NOTHING;
endif;

if (IsObject(objSite)) then
set objSite = NOTHING;
endif;

return nvReturn;

end;


///////////////////////////////////////////////
// get the next available Site id
///////////////////////////////////////////////
function GetNextWebSiteID(szWebSiteName, nvSiteID, bFound)
OBJECT objW3SVC, objSite;
NUMBER nvReturn, nSiteID;
STRING szMsg, szSiteID;
STRING szIPAddress;
BOOL bTrue;
begin

nvReturn = 0;

//we'll loop through until we get an error
//that'll then be the available one...
bTrue = FALSE;
bFound = FALSE;
nSiteID = 1;
set objW3SVC = CoGetObject("IIS://LocalHost/W3SVC", "");
if (IsObject(objW3SVC)) then
//MessageBox("Success getting objW3SVC object\nWebRoot Name: " +objW3SVC.Name, INFORMATION);
while (bTrue==FALSE)
NumToStr(szSiteID, nSiteID);
try
set objSite = CoGetObject("IIS://LocalHost/W3SVC/"+szSiteID, "");
if (IsObject(objSite)) then
//MessageBox("Success getting objSite object\nWebRoot Name: " +objSite.ServerComment, INFORMATION);
//is this website already installed? if so, use it if the user has passed a value
if (szWebSiteName != "") then
if (objSite.ServerComment == szWebSiteName) then
//MessageBox(objSite.ServerComment + " found! Will upgrade this site", INFORMATION);
bFound = TRUE;
bTrue = TRUE;
endif;
endif;
endif;
catch
MessageBox("Failed getting objW3SVC object - siteid: " +szSiteID, INFORMATION);
abort;
endcatch;
if (bTrue == FALSE) then
try
set objSite = objW3SVC.GetObject("IIsWebServer", nSiteID); //nvSiteIndex);
if (IsObject(objSite)) then
//MessageBox("Success getting objSite object", INFORMATION);
nSiteID = nSiteID + 1;
else
MessageBox("Couldn't get objSite object", INFORMATION);
endif;
catch
szMsg = "SiteID: " + szSiteID + " doesn't exist - we'll use this";
//MessageBoxEx(szMsg, "IIS Configuration Error", INFORMATION);
//set the flag to say we've found our next available site id
bTrue = TRUE;
endcatch;
//sanity check
if (nSiteID > 1000) then
szMsg = "Unable to find the next available website id\nUnable to create websites. Please create them manually.";
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
bTrue = TRUE;
endif;
endif;
endwhile;
else
MessageBox("Couldn't get objW3SVC object in function: GetNextSiteID", SEVERE);
endif;

if (IsObject(objW3SVC)) then
set objW3SVC = NOTHING;
endif;

if (IsObject(objSite)) then
set objSite = NOTHING;
endif;

if (bTrue==FALSE) then
nvSiteID = 0;
return 1;
else
if (nSiteID > 1000) then
//didn't find the next number
nvSiteID = 0;
return 1;
else
nvSiteID = nSiteID;
return 0;
endif;
endif;

end;

/////////////////////////////////////////////////////
// Creates a website using a given siteid
/////////////////////////////////////////////////////
function CreateWebSite(nvSiteID, szName, szPort, szHostHeader, szIPAddress)
OBJECT objW3SVC, objSite, objDir;
NUMBER nvReturn, nDelay, nCount;
STRING szComputerName, szBindings, szInfo, szMsg, szSiteID, szVal;
STRING szIPAddress;
BOOL bTrue;
begin

nDelay = 2;
szVal = 'Creating Website ' +szName+'. Please wait ...';
SdShowMsg ( szVal, TRUE );
Delay(nDelay);

nvReturn = 0;
//convert our site id to a string
NumToStr(szSiteID, nvSiteID);
if (nvReturn == 0) then
//create the website using our siteid
set objW3SVC = CoGetObject("IIS://LocalHost/W3SVC", "");
if (IsObject(objW3SVC)) then
try
set objSite = objW3SVC.Create("IIsWebServer", nvSiteID);
objSite.SetInfo;
set objSite = NOTHING;
catch
szMsg = "Unable to create new website using SiteID: " + szSiteID;
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
nvReturn = 1;
endcatch;
else
MessageBox("Couldn't get objW3SVC object in function: CreateWebSite", SEVERE);
endif;

endif;

if (nvReturn == 0) then
//Verify that the newly created site can be retrieved
try
set objSite = CoGetObject("IIS://LocalHost/W3SVC/" + szSiteID, "");
catch
szMsg = "Unable to retrieve newly created website using SiteID: " + szSiteID;
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
nvReturn = 1;
endcatch;
endif;

if (nvReturn == 0) then
try
//create the bindings
szBindings = szIPAddress + ":" + szPort + ":" + szHostHeader;
objSite.ServerBindings = szBindings;
objSite.ServerComment = szName;
objSite.SetInfo;
nvReturn = 0;
catch
szMsg = "Unable to attach Port & HostHeader to\nthe newly created website";
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
nvReturn = 1;
endcatch;
endif;

if (nvReturn == 0) then
//Create the link to its root directory
try
set objDir = objSite.Create("IISWebVirtualDir", "ROOT");
objDir.Path = TARGETDIR;
objDir.AccessRead = TRUE;
objDir.AppFriendlyName = "Default Application";
objDir.SetInfo;
catch
szMsg = "Unable to set root directory to: " + TARGETDIR;
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
nvReturn = 1;
endcatch;
endif;

if (nvReturn == 0) then
//Set the application protection (TRUE = "High", FALSE = "low")
try
try
objDir.AppCreate2(0);
//MessageBox("Set application protection to 0 (IIS 5)", WARNING);
catch
objDir.AppCreate(FALSE); //(TRUE);
//MessageBox("Set application protection to FALSE (IIS 4)", WARNING);
endcatch;
objDir.SetInfo;
catch
szMsg = "Unable to set Application Protection level for: " + szName;
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
nvReturn = 1;
endcatch;
endif;

if (nvReturn == 0) then
//Try to set the execute permissions
try
//this combination sets "Scripts Only"
objDir.AccessScript = TRUE;
objDir.AccessExecute = FALSE;
objDir.SetInfo;
catch
szMsg = "Unable to set application Execute Permissions for: " + szName;
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
nvReturn = 1;
endcatch;
endif;

if (IsObject(objW3SVC)) then
set objW3SVC = NOTHING;
endif;

if (IsObject(objSite)) then
set objSite = NOTHING;
endif;

if (IsObject(objDir)) then
set objDir = NOTHING;
endif;

SdShowMsg ( szVal, FALSE );

return nvReturn;

end;

//////////////////////////////////////////////////////////
// create a virtual directory using the siteid
//////////////////////////////////////////////////////////
function CreateVirtualDirectory(nvSiteID, szName, bUpgrade)
OBJECT objDir, objSite, objW3SVC;
NUMBER nvReturn, nDelay, nCount;
STRING szComputerName, szBindings, szInfo, szMsg, szSiteID, szVal;
begin

nDelay = 2;
szVal = 'Creating Virtual Directory ' +szName+ '. Please wait ...';
SdShowMsg ( szVal, TRUE );
Delay(nDelay);

NumToStr(szSiteID, nvSiteID);
try
//Get our Web Site Object
set objSite = CoGetObject("IIS://LocalHost/W3SVC/" + szSiteID +"/ROOT", "");
catch
szMsg = "Unable to retrieve website using SiteID: " + szSiteID;
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
nvReturn = 1;
endcatch;

if (nvReturn == 0) then
//Create the virtual directory
try
set objDir = objSite.Create("IISWebVirtualDir", szName);
objDir.Path = TARGETDIR ^ '\\' ^ szName;

objDir.AppFriendlyName = szName;
objDir.AccessRead = TRUE;
objDir.SetInfo;
catch
//surpress message if upgradeing
if (bUpgrade!=TRUE) then
szMsg = "Unable to create virtual directory for: " + szName +"\nPlease check to ensure it doesn't already exist";
MessageBoxEx(szMsg, "IIS Configuration Error", WARNING);
endif;
nvReturn = 1;
endcatch;
endif;

if (nvReturn == 0) then
//Set the application protection (TRUE = "High", FALSE = "low")
try
try
objDir.AppCreate2(0);
//MessageBox("Set application protection to 0 (IIS 5)", WARNING);
catch
objDir.AppCreate(FALSE); //(TRUE);
//MessageBox("Set application protection to FALSE (IIS 4)", WARNING);
endcatch;
objDir.SetInfo;
catch
szMsg = "Unable to set Application Protection level for: " + szName;
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
nvReturn = 1;
endcatch;
endif;

if (nvReturn == 0) then
//Try to set the execute permissions
try
//this combination sets "Scripts Only"
objDir.AccessScript = TRUE;
objDir.AccessExecute = FALSE;
objDir.SetInfo;
catch
szMsg = "Unable to set application Execute Permissions for: " + szName;
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
nvReturn = 1;
endcatch;
endif;

//MessageBox("Now Check the IIS value for ExecutePermissions for this webserver", INFORMATION);

if (IsObject(objSite)) then
set objSite = NOTHING;
endif;

if (IsObject(objDir)) then
set objDir = NOTHING;
endif;

SdShowMsg ( szVal, FALSE );

return nvReturn;

end;

///////////////////////////////////////////////////
// start a website using the siteid
///////////////////////////////////////////////////
function StartWebService(nvSiteID)
OBJECT objDir, objSite;
NUMBER nvReturn, nDelay, nCount;
STRING szComputerName, szBindings, szInfo, szMsg, szSiteID, szVal;
begin

nDelay = 2;
szVal = 'Starting Web Site. Please wait ...';
SdShowMsg ( szVal, TRUE );
Delay(nDelay);

nvReturn = 0;
NumToStr(szSiteID, nvSiteID);
try
set objSite = CoGetObject("IIS://LocalHost/W3SVC/" + szSiteID, "");
catch
szMsg = "Unable to retrieve newly created website using SiteID: " + szSiteID;
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
nvReturn = 1;
endcatch;

if (nvReturn == 0) then
try
objSite.Start;
catch
szMsg = "Unable to start website using SiteID: " + szSiteID;
MessageBoxEx(szMsg, "IIS Configuration Error", SEVERE);
nvReturn = 1;
endcatch;
endif;

if (IsObject(objSite)) then
set objSite = NOTHING;
endif;

SdShowMsg ( szVal, FALSE );

return nvReturn;

end;

Sa'di Tahboub
02-02-2005, 06:39 AM
HI All,

I used the CreateVirtualDirectory () for the default web site and it is working fine, but actually I'm using a win 2000 Pro and Win Xp Pro, so can i create a new web site on these OS, in other work can i use CreateWebSite (..) & GetNextWebSiteID (..), i need to upgrade to Windows server to let that allowable. actually i'm thinking to enumarate all existence web site in a list box to let my user to select any web site and then to install my services..

I read that it is not allowable to add new web site with IIS in Win2000 Pro and Win XP Pro.
http://www.microsoft.com/windows2000/en/professional/iis/default.asp?url=/windows2000/en/professional/iis/htm/core/iifaq.htm.



Regards

Baggies
02-02-2005, 06:57 AM
For my installers I detect the operating system and when installing on XP Pro or 2000 Pro I do not allow the user to enter a custom website name and instead silently set it to "Default Web Site" instead - I then use the same process using the same functions as I've posted on this forum to detect and upgrade this web site.

It is technically possible to install to a custom site name on XP Pro however you have to stop and disable the Default Web Site first, which to be honest proved to be too much a pfaf to get to work correctly in the time I had, especially when considering 99% of my users are using 2003Server (which does allow the naming of custom websites which can run concurrent to the Default Web Site), the 1% using XP Pro being quite happy to have the new virtual folders installed to the Default Web Site.

I'm pleased you've found a use for the scripts!

Sa'di Tahboub
02-02-2005, 08:04 AM
Hi Baggies,

Thanks for your answering. but i still need a help from you and i'm in hope that you will do

Now i put in mind to do the following?
i want to create a custom dialog and before displaying it i want to detect the operating system of the user and so on if the user is working under Windows Server then i want to enumerate the existence web sited in a list control.

can you post install script for that(enumerate), i need to pass the ID for the selected site then i can use it in CreateVirtualDirectory(SelectedSiteID,......).


best regards

Baggies
02-02-2005, 08:35 AM
For operating system, do a check of SYSINFO.WINNT:

SYSINFO.WINNT.bWinNT - If TRUE, OS is Windows NT (includes Windows 2000 and Windows XP).
SYSINFO.WINNT.bWinNT4 - If TRUE, OS is Windows NT 4.0.
SYSINFO.WINNT.bWinXP - If TRUE, OS is Windows XP.
SYSINFO.WINNT.bWin2000 - If TRUE, OS is Windows 2000.
SYSINFO.WINNT.bWinServer2003 - If TRUE, OS is Windows Server 2003.

Unfortunately, time restricts me being able to help with your other request. If it's of help, here's the link to Chris Cowes' ADSI scripts that I abused for the functions I've posted here - you'll probably find what you require here and as you can see it doesn't take much to port them:

http://www.iisfaq.com/Default.aspx?tabid=2538


Good luck

Sa'di Tahboub
02-03-2005, 03:35 AM
Hello,

Any chance for update news , i found through the forum a VB script for that, but i didn't find some one ported it to InstallScript !!!!

also i found some releated code in http://www.iisfaq.com/Default.aspx?tabid=2766, but still need a help how to port it to InstallScript. :mad:

thx

Perucho
02-03-2005, 03:12 PM
read this post for OS SYSINFO: http://community.installshield.com/showthread.php?t=140457

Sa'di Tahboub
02-06-2005, 01:56 PM
Hi All ,

here is a DLL solving the "FOR EACH" problem to be used in installscript, i used it and and used the attached sample to enumerate files in the C:\ , and it is working fine, but can someone get the benefit of the code to enumerate the web sites.

regards

MrKeut
10-20-2005, 10:36 AM
Hi,

To set the host header you need to set the IIS Web site port number to port:header_name e.g. 80:header.co.uk

Hope this helps..

Cheers

Jo
From what i've read I'm sure it would be better to set my web site header in IIS using script but i'm not familiar with this.
So when i use this method:
port:header_name
I got a ":" added at the end of my header
in this case it would be "header_name:" :confused:

Have anyone got an idea ?

Thanks

Quentin

narmadachebrolu
03-27-2006, 04:07 PM
The same with me i am also getting ":" at the end of header name... please post if anybody resolved this.

Thanks,
narmada.