« Previous Next »

Answered Thread: configure Wild card SSL for subdomain programatically in web application

Last post 11-05-2009 1:30 PM by Richard Grenfell. 6 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (7 items)

Sort Posts:

  • 11-25-2008, 8:40 AM

    configure Wild card SSL for subdomain programatically in web application

     My web application creates subdomains(sites) under a the main domain say www.mydomain.com. Web server is installed with IIS 6.0. I have installed wildcard SSL for www.mydomain.com. When my app creates a sudomain say www.in.mydomain.com the SSL should be applied automatically in the port 443. But it is not happening when the subsite starts running.So I ran the adminscript(adsutil.vbs) using csript.exe in cmd prompt manually for each sub domain. ,  since it si a metabase property.

    cscript.exe adsutil.vbs set /w3svc/2063634474/SecureBindings ":443:testsgs.cme.edu"

    where 2063634474 is site ID in IIS

    Only then the SSL gets ebnabled which doesn't fulfil the requirement. so please let me know if u got solution for this.ie ebnabling ssl for subdomains should be automated from the web application itself while the site is created itself.

    Thanks in advance.

    gomathi

  • 12-01-2008, 9:56 PM In reply to

    Re: configure Wild card SSL for subdomain programatically in web application

    Sincerely
    Microsoft Online Community Support
    Andrew Zhu - MSFT


    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • 12-01-2008, 11:48 PM In reply to

    Re: configure Wild card SSL for subdomain programatically in web application

    Hi,

    thanks for the link sent.

    But my application needs to run the cscript.exe from inside the aspx page itself and not from the command prompt. ie while the subdomain gets created, the 443 port also should be enabled. see my coding to create sub domain

    public static bool CreateNewWebsite(WebSiteInfo WebsiteInformation)

    {

    string strIISPath = WebSiteInfo.IIS + WebsiteInformation.ServerName + WebSiteInfo.WEBSERVICE;

    // Check if path points to any existing directory

    if (IsExist(strIISPath))

    {

    // Create Directory entry at root level

    DirectoryEntry objDirectoryEntry = new DirectoryEntry(strIISPath);

     

    objDirectoryEntry.RefreshCache();

     

    //return false if the website is already exists

    string strWebSiteID = GetSiteID(strIISPath, WebsiteInformation.SiteName);if (string.IsNullOrEmpty(strWebSiteID))

    {

    // Create object for site specification

    object[] objNewSite = new object[] { WebsiteInformation.SiteName, new object[] { WebsiteInformation.HostHeader }, WebsiteInformation.PhysicalPath };

    // Invoke create site method.

    objDirectoryEntry.Invoke("CreateNewSite", objNewSite);

    // Save newly created directory.

    objDirectoryEntry.CommitChanges();

    // close directory entry.

    objDirectoryEntry.Close();

    // Create entry point new website

    objDirectoryEntry = new DirectoryEntry(strIISPath + "/" + GetSiteID(strIISPath, WebsiteInformation.SiteName));

    // Assign property to Website

    objDirectoryEntry.Properties["EnableDirBrowsing"][0] = WebsiteInformation.HasBrowseAccess;

    objDirectoryEntry.Properties["AccessExecute"][0] = WebsiteInformation.HasExecuteAccess;

    objDirectoryEntry.Properties["AccessRead"][0] = WebsiteInformation.HasReadAccess;

    objDirectoryEntry.Properties["AccessWrite"][0] = WebsiteInformation.HasWriteAccess;

    objDirectoryEntry.Properties["AuthAnonymous"][0] = WebsiteInformation.IsAnonymousAccessAllow;

    objDirectoryEntry.Properties["AuthBasic"][0] = WebsiteInformation.IsBasicAuthenticationSet;

    objDirectoryEntry.Properties["AuthNTLM"][0] = WebsiteInformation.IsNTLMAuthenticationSet;

    objDirectoryEntry.Properties["DefaultDoc"][0] = WebsiteInformation.DefaultDoc;

    objDirectoryEntry.Properties["AppPoolId"][0] = "Informed";

    //objDirectoryEntry.Properties["SecureBindings"][0] = ":443:";

    // Save Changes

    objDirectoryEntry.CommitChanges();

    // Close both directory object.

    StartWebSite(WebsiteInformation.ServerName, WebsiteInformation.SiteName.ToString());

    objDirectoryEntry.Close();

    return true;

    }

    else

    {

    return false;

    }

    }

    else

    return false;

    }

     objDirectoryEntry.Properties["SecureBindings"][0] = ":443:";  - this has to set the port 443 for the SSL to get enabled. it throws err so ran the csript.exe manaually from the DOS prompt

    My client wants site creation and SSL port settings should be done at the same time programatically when he clicks the button " Create Site " . So tell how run the script from the aspx page itself. If you have come across this situation please help me.

    Thanks

    gomathi

     

     

     

  • 12-02-2008, 5:54 AM In reply to

    Re: configure Wild card SSL for subdomain programatically in web application

    Hi,

    Did you tried IIsCertMapper class?

    http://msdn.microsoft.com/en-us/library/ms525989.aspx

    convert vb.net to c#

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    another way comes to my mind:

    generate WMI string(like you give in your post )dynamicly, provide customized Site ID .etc

    cscript.exe adsutil.vbs set /w3svc/2063634474/SecureBindings ":443:testsgs.cme.edu"

    save it in a bat file, and call the bat file from page.

     Hope this helps

    Thanks

    Sincerely
    Microsoft Online Community Support
    Andrew Zhu - MSFT


    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • 12-03-2008, 5:20 AM In reply to

    Re: configure Wild card SSL for subdomain programatically in web application

    Hi,

    try to run your bat file by using cmd.exe

    take a look at this thread.

    http://forums.iis.net/t/1153383.aspx

    Hope this will help you.

    You can post your result here. and we will try to help you as we can.

    Thanks

    Sincerely
    Microsoft Online Community Support
    Andrew Zhu - MSFT


    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • 12-05-2008, 9:30 AM In reply to

    • icsinc
    • Not Ranked
    • Joined on 12-05-2008, 2:09 PM
    • Posts 1

    Re: configure Wild card SSL for subdomain programatically in web application

    I am working on this now as well.  I came across a similar (maybe the same) exception:
     
    System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Array'.
     

    I eventually found that the SecureBindings property needs an array of SecureBinding objects.
    http://msdn.microsoft.com/en-us/library/ms524332.aspx

    However, the link to the SecureBindings metabase description didn't really help.  It wasn't until I found the information this page that it clicked for me.
    http://msdn.microsoft.com/en-us/library/ms525948.aspx
    SecureBindings appear to be progmatically handled in a manner similar to the SeverBindings when creating the site.


    In my case (using 2.0 framework) it was the following:


            Dim site As ManagementObject = query.ExecuteScalar()
            site.SetPropertyValue("AppFriendlyName", domain)
            site.SetPropertyValue("AccessRead", True)
            site.SetPropertyValue("AccessScript", True)
            site.SetPropertyValue("AnonymousUserName", username)
            site.SetPropertyValue("AnonymousUserPass", password)
            site.SetPropertyValue("AuthNTLM", True)
            site.SetPropertyValue("EnableDirBrowsing", False)

            'anonomys access
            site.SetPropertyValue("AuthAnonymous", True)

            'secure bindings to wild card ssl
            Dim sbindingsClass As New ManagementClass(scope, New ManagementPath("SecureBinding"), Nothing)
            Dim sbindings As ManagementObject = sbindingsClass.CreateInstance()
            sbindings.SetPropertyValue("Port", "443")

            site.SetPropertyValue("SecureBindings", New Object() {sbindings})


            site.Put()


    Hopefully this helps


  • 11-05-2009, 1:30 PM In reply to

    Answered Re: configure Wild card SSL for subdomain programatically in web application

    I ran into this same problem yesterday.  The problem turned out to be that the SecureBindings property does not exist after Invoking CreateWebSite.  This means you can't access the property through the Properties object.  Instead you must call another method.

    objDirectoryEntry.Invoke( "Put", "SecureBindings", ":443:" );

    objDirectoryEntry.Invoke( "SetInfo" );

    Don't leave out the SetInfo call, that commits any items that you have "Put".  The next step if you want to require SSL is also to call:

    DirectoryEntry siteRoot  = new DirectoryEntry( string.Format( strIISPath + "/" + GetSiteID(strIISPath, WebsiteInformation.SiteName) + "/ROOT" );

    siteRoot.Invoke( "Put" "AccessSSLFlags", 0x0100 | 0x0008 );  // Whichever flags you want to require here

    siteRoot.Invoke( "SetInfo" );

    siteRoot.CommitChanges();

Page 1 of 1 (7 items)
Microsoft Communities