locked
How to get website RRS feed

  • Question

  • User1836507724 posted
    Hi I'm using a asp.net application to configure IIS Websites via Browser. I can create and configure new Websites using the DirectoryEntry.Invoke() Method. The problem is, when a website already exists and I only know its Name and not its ID I can't get a reference to it. Somebody knows how to do that? Thank you Jan
    Friday, June 18, 2004 9:32 AM

All replies

  • User-1036928387 posted
    The best way I've found to do this is to search the metabase. You'll need to enumerate the indices and then connect to each, checking the ServerComment property if you know what the description you set was or you can check the bindings for the domain name/ip to correlate domain name to index. You should look at assigning your own index when you create a site and associate it to the virtual you've created in a db. Sorry, the only example I have is written in Perl; I haven't had to do this yet in C# since I assign my own index to the sites and track them via a provisioning database. But, this should give you a nudge in the right direction. <---snip--> use strict; use Win32::OLE; my @indices; my $domain = shift; # the domain for which you need the index. eval { my $obj = Win32::OLE->GetObject("IIS://localhost/W3SVC"); OBJ: for my $i (in $obj) { if($i->Name =~ /\d/) { push(@indices,$i->Name); } } }; if (Win32::OLE->LastError) { print "Failed to bind to the metabase.\n"; } for my $index (@indices) { my $obj = Win32::OLE->GetObject("IIS://localhost/W3SVC/$index"); my $val = $obj->{ServerComment}; if($val =~ /$domain/i) { print "$index\n"; } } <--snip--> You could also use System.DirectoryServices to enumerate the metabase. You can also explore using WMI. The above code will work for IIS 4 - 6. Hope this helps. -matt
    Friday, June 18, 2004 2:16 PM