« Previous Next »

Thread: Adding Another Identity To A Site Programmatically

Last post 09-10-2008 8:56 AM by aaabbbccc. 5 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (6 items)

Sort Posts:

  • 01-10-2008, 11:36 AM

    • mshabib
    • Top 500 Contributor
    • Joined on 11-27-2007, 5:37 PM
    • Posts 15

    Adding Another Identity To A Site Programmatically

    I need to programmatically (via .NET) add a new identity to a website but I'm not sure how to do so. I think I may have to add a custom header, but I'm not positive. I can do it via IIS's management tool by adding another identity to my website.

     

    When I create a website, I do it on a specific port so it is something like

     

    www.mydomain.com:XXXX

     

    where XXXX is my port number.

     

    So what I need is to add a second identity to the website in IIS (6.0) so that I can access it via another port (say, 80) but through a different "host header value", along the lines of

     

    WEBSITENAME.mydomain.com

     

    Any tips?

     

    Thanks much.

    Mustafa


     

  • 01-23-2008, 12:58 PM In reply to

    • mvolo
    • Top 25 Contributor
    • Joined on 09-17-2003, 1:48 PM
    • Philadelphia, PA
    • Posts 584
    • IIS MVPs

    Re: Adding Another Identity To A Site Programmatically

    Hi Mustafa,

    You need to add a new binding to your web site.  You can do this using WMI by doing soming like this:

    1) Create an instance of the IIsWebServerSetting class for the web site path you need

    Set objSite = objWMIService.Get("IIsWebServerSetting='" & strSitePath & "'")

    2) Access the array of ServerBinding objects from the ServerBindings propertyof the IIsWebServerSetting.

    Set objBindings =  objSite.ServerBindings;

    3) Create a new ServerBinding for your binding.

    ...

    4) Set the resulting array back to the ServerBindings  property.

    objSite.ServerBindings = objBindings

    objSite.SetInfo

     

    Thanks,

    Mike Volodarsky

    Program Manager
    IIS Core Server
    Visit mvolo.com for more IIS 7.0 posts, tools, and info

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 01-28-2008, 3:57 PM In reply to

    • mshabib
    • Top 500 Contributor
    • Joined on 11-27-2007, 5:37 PM
    • Posts 15

    Re: Adding Another Identity To A Site Programmatically

     thanks much, will the same sort of idea work if i'm doing the programming via c#?     

  • 01-28-2008, 5:11 PM In reply to

    • mvolo
    • Top 25 Contributor
    • Joined on 09-17-2003, 1:48 PM
    • Philadelphia, PA
    • Posts 584
    • IIS MVPs

    Re: Adding Another Identity To A Site Programmatically

    Sure, you'll need to use .NET WMI objects (System.Management.ManagementClass).  Alternatively, you can also use the ADSI interfaces from .NET as well.

    Thanks,

    Mike Volodarsky

    Program Manager
    IIS Core Server
    Visit mvolo.com for more IIS 7.0 posts, tools, and info

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 01-29-2008, 5:27 AM In reply to

    Re: Adding Another Identity To A Site Programmatically

    Hi mvolo,

    I'm not verry into VB Scripting for IIS. But I read your post and I'm wondering do I realy have to add the bindings with an array?

    I tried that but it just not get it to work.

    My code is:

    'CMD Line Parameters used in this scrip
    Dim WSiteNumber, DomainName, ProductID, DefaultAppPoolID, AdditionalBinding
    Dim objWebApp, intArraySize, arrOldBindings, arrNewBindings

    Const SiteRootPath = "D:\Sites" 'Edit to specify the sites root folder


    'Set CMD Line parameters in Global Variables
    Sub GetParams()
            ProductID         = WScript.Arguments(0)
            WSiteNumber   = WScript.Arguments(1)
            DefaultAppPoolID  = WScript.Arguments(2)
            DomainName        = WScript.Arguments(3)
     WScript.Echo ProductID
    AdditionalBinding = ProductID & ".server1.mydomain.dir"
    End Sub

    Sub UpdateServerBindings()

          
        Set IIsWebVSiteObj = GetObject("IIS://localhost/w3svc/" & ProductID)
        
        
         If isArray(IIsWebVSiteObj.ServerBindings) then

         arrOldBindings = IIsWebVSiteObj.ServerBindings
         intArraySize = UBound(arrOldBindings)
         Redim arrNewBindings(intArraySize + 1)
         
        For i = 0 to intArraySize
        arrNewBindings(i) = arrOldBindings(i)
        
        Next
        
        arrNewBindings(intArraySize + 1) = ":" & AdditionalBinding & ":"

        IIsWebVSiteObj.Put "ServerBindings", (arrNewBindings)
        IIsWebVSiteObj.SetInfo

        End If

    End Sub  

    The host header just stays the default.

    Am I missing something?

     Thanx for your time

  • 09-10-2008, 8:56 AM In reply to

    Re: Adding Another Identity To A Site Programmatically

    Hi Mike,

    I'm new to WMI, can you post a fully code sample in C# of the subject,

    Or direct me to a website which offers such solution?

    thanks,

    Guy

Page 1 of 1 (6 items)
Microsoft Communities