Subject: create subdomain
Posted By: keyvanjan Post Date: 1/9/2006 5:47:52 AM
Hi,
How can I create subdomain programatically through asp code?
Ihave seen this on some weblogs.
when the user registers  a subdomain is created for him like this
Username.Sitename.com

Thanks in advance for your help


Reply By: Imar Reply Date: 1/9/2006 12:18:12 PM
Hi there,

You can use ADSI to program against the IIS configuration. It can be difficult to find out what properties you need to set, but it's quite possible to do this.

Here are some pointers:

http://www.west-wind.com/presentations/WebServerConfig/WebServerConfig.htm
http://www.microsoft.com/windows2000/en/server/iis/default.asp?url=/windows2000/en/server/iis/htm/asp/aore94th.htm
http://www.iisfaq.com/Default.aspx?tabid=2537

In addition to this, you'll need a * record for your domain pointing to your machine. That means whatever you type in before your domain name should bring you to your server. Then you can use ADSI to create new websites and set the host header to SomeName.YourDomain.Com

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply By: keyvanjan Reply Date: 1/9/2006 5:56:14 PM
THANKS IMar

Reply By: savan_thakkar Reply Date: 2/26/2006 2:09:40 PM
Hi keyvanjan & Imar...
I checked the links....
But I could not create subdomain through C#,asp.net application.
Can u please explain me in a bit detail...
Thanks.

Savan
Reply By: keyvanjan Reply Date: 2/27/2006 2:14:23 AM
Unfortunately I could not either .I just got an idea but it seems it does not work.
It seems noBody can answer this question

Reply By: Imar Reply Date: 2/27/2006 3:25:26 AM
How does the code look like that you have been using??

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply By: savan_thakkar Reply Date: 2/28/2006 1:03:02 AM
Hi,
This is the code that I m using...

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       CreateVirtualDir("savan", "sampletest", "D:\Savan\Backup\ChoicesWildNet\Application Sohel")
End Sub

Private Sub CreateVirtualDir(ByVal WebSite As String, ByVal AppName As String, ByVal Path As String)

        Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/Schema/AppIsolated")
        'Dim CanCreate As Boolean = Not IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"
        IISSchema.Dispose()

        '  If CanCreate Then
        Dim PathCreated As Boolean

        Try
            Dim IISAdmin As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/W3SVC/1/Root")

            'make sure folder exists
            If Not System.IO.Directory.Exists(Path) Then
                System.IO.Directory.CreateDirectory(Path)
                PathCreated = True
            End If

            'If the virtual directory already exists then delete it
            For Each VD As System.DirectoryServices.DirectoryEntry In IISAdmin.Children
                If VD.Name = AppName Then
                    IISAdmin.Invoke("Delete", New String() {VD.SchemaClassName, AppName})
                    IISAdmin.CommitChanges()
                    Exit For
                End If
            Next VD

            'Create and setup new virtual directory
            Dim VDir As System.DirectoryServices.DirectoryEntry = IISAdmin.Children.Add(AppName, "IIsWebVirtualDir")
            VDir.Properties("Path").Item(0) = Path
            VDir.Properties("AppFriendlyName").Item(0) = AppName
            VDir.Properties("EnableDirBrowsing").Item(0) = False
            VDir.Properties("AccessRead").Item(0) = True
            VDir.Properties("Acces****ecute").Item(0) = True
            VDir.Properties("AccessWrite").Item(0) = False
            VDir.Properties("AccessScript").Item(0) = True
            VDir.Properties("AuthNTLM").Item(0) = True
            VDir.Properties("EnableDefaultDoc").Item(0) = True
            VDir.Properties("DefaultDoc").Item(0) = "default.htm,default.aspx,default.asp"
            VDir.Properties("AspEnableParentPaths").Item(0) = True
            VDir.CommitChanges()

            'the following are acceptable params
            'INPROC = 0
            'OUTPROC = 1
            'POOLED = 2
            VDir.Invoke("AppCreate", 1)

        Catch Ex As Exception
            If PathCreated Then
                System.IO.Directory.Delete(Path)
            End If
            Response.Write(Ex.Message.ToString())
        End Try
        ' End If
    End Sub

Savan
Reply By: savan_thakkar Reply Date: 2/28/2006 1:59:27 AM

It would be better if you can tell me What type of permission need to be set in IIS
in order to create Virtual Directory in this way.

Thanks


Savan
Reply By: Imar Reply Date: 2/28/2006 4:30:15 PM
I am not 100% user, but I think you need Administrative privileges, or at least that of a Power User.

However, it's easy to find out using Windows XP's Run As feature.

Compile your code in an exe and run it with different user accounts....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Help Me Lift You Up by This Mortal Coil (Track 15 from the album: Blood) What's This?
Reply By: maulik@hitechinfosoft.com Reply Date: 5/15/2006 6:45:40 AM
Hello Savan_thakkar

I have faced the samw problem as U.
I eannt to create the subdomain through ASP.Net

For ex. Suppose my site name is www.xxx.com and one of my client register with his firm name as "yyy". So domain for his site would be "www.yyy.xxx.com"

Reply By: Surjit Reply Date: 4/18/2008 11:11:17 PM
How can i create subdomain dynamically using classic ASP code like username.domainname.com
Can anyone help me.

Thanks in advance

Reply By: Imar Reply Date: 4/19/2008 7:20:01 AM
Hi Surjit,

Aren't the answers to that question in this post, and the other code you posted in a different thread?

Your code is probably fine, but the user account to execute it (probably IUSR_MachineName) doesn't have the necessary permissions to execute it.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply By: Surjit Reply Date: 4/21/2008 12:13:08 AM
Thanks Imar,

  I really appreciate your help, can you explain me in details.
   Actually i want to create subdomain dynamically using ASP Code and i am facing the error here.Please advice.
  
'Setup Connections To IIS
set locatorObj = CreateObject("WbemScripting.SWbemLocator")
set providerObj = locatorObj.ConnectServer(strServer,"root/MicrosoftIISv2")
set serviceObj = providerObj.Get("IIsWebService='W3SVC'")

it give error
SWbemLocator error '80041003'
Access denied

And when i pass the Username and password for web Server
set providerObj = locatorObj.ConnectServer(strServer, "root/MicrosoftIISv2",strUser, strPassword)

it give error
SWbemLocator error '80041064'

User credentials cannot be used for local connections

Thanks,
Surjit


Reply By: Imar Reply Date: 4/21/2008 12:46:11 AM
Like I said, make sure that the account that executes this code has sufficient permissions. It's not about setting permissions for the site you are creating; it's about permissions for the code that creates the site.

You may want to take a look here for some ideas: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=290

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

Go to topic 70765

Return to index page 1