Thursday, November 02, 2006

HOWTO: Change the ID of an IIS Website

Question:

Hello,

When I install Sharepoint Services, it creates a web site with an identifier. (Ex. ID 4).

I need to change that ID for another one. So I use this command :

cscript adsutil.vbs move w3svc/4 w3svc/4243.

It does the trick...

But, when I look in IIS I see that the site is stopped and I have this error in the event logs:

Event Type:           Error 
Event Source: W3SVC
Event Category: None
Event ID: 1007
Date: 2006-10-25
Time: 13:19:46
User: N/A
Computer: U1U206V
Description:

Cannot register the URL prefix 'http://*:24051/' for site '42'. The
necessary network binding may already be in use. The site has been
deactivated. The data field contains the error number.

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

Data:
0000: b7 00 07 80 ·..€

If I start the site manually, the site starts fine with no errors.

I just want to know if there's a way to not receive this error message when I change the ID of my site.

Can someone confirm that?

Or is there another way to do it to prevent errors?

Thx in advance for your help.

Answer:

The reason you get that error event when you MOVE a running website is due to how ADSUTIL.VBS MOVE works. You can treat the MOVE operation as a non-atomic COPY-then-DELETE... because it is designed to move arbitrary metabase nodes (for example, one vdir to another vdir in a different tree hierarchy).

Thus, when you use it to move from website ID 4 to website ID 42, what happens is this:

  1. The entire metabase node under website ID 4 is copied to website node with ID 42
  2. Since website ID 4 is running and website node with ID 42 is a website, website ID 42 also attempts to run
  3. However, since both website nodes are duplicates and have the exact same bindings, the new website ID 42 cannot start due to duplicate bindings and trigger the error event
  4. After website ID 42 finishes copying, node ID 4 is deleted
  5. But website ID 42 has already failed to start; there is no state change here

The key is to STOP the source website ID prior to executing the MOVE. In that case, there will be no duplicate bindings simultaneously running during the COPY-the-DELETE, and one will not see the error event.


CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs STOP_SERVER W3SVC/4
CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs MOVE W3SVC/4 W3SVC/42
CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs START_SERVER W3SVC/42

//David

3 comments:

jim said...

Can you use names for the ID's instead of the numbers? If so can you epxlain? I want to be able to find the directory to grep a log quicker instead of an id number for each web site (since I run several)

Thanks

Jim

David Wang said...

IIS uses an ID number to uniquely identify websites. Each website has a "Friendly name" associated with it, and this "Friendly name" is what the UI displays.

You can certain use the "Friendly name" to search and map back to an ID number, but internally all operations have to be made with the ID number.

I am not certain what you mean by "I want to be able to find the directory to grep a log quicker instead of an id number for each website".

The IIS log file uses the website ID, which is the easiest way to map back to a directory. You can use the ID to map back to a "Friendly name" if you want.

//David

Mike Hunsaker said...

This also helped me resolve an issue with Exchange 2007 and Outlook Anywhere. The cmdlet Enable-OutlookAnywhere was failing because I had no website at /W3SVC/1/ROOT.

I used the commands here to move my website and was able to enable outlook anywhere.

I did have to go into ADSIedit and update the MetaBasePath for my existing OWA sites to adjust for the moved website.