Inam Ur Rehman
Inam Ur Rehman

Reputation: 154

Create sub domain on different server in asp.net

I want to create sub-domain in asp.net. On local IIS server it is working fine and code generates a new website. The problem is, I want to create websites on Server(another pc).The following code generates website on local IIS server. Here is my code. Thanks in advance for any help.

 private void createDomain(string domainName, string subDomainName)
        {
            try
            {
                ServerManager serverMgr = new ServerManager();
                string strWebsitename = subDomainName+"." +domainName ; // abc
                string strApplicationPool = "ASP.NET v4.0";  // set your deafultpool :4.0 in IIS
                string strhostname = subDomainName + "." + domainName; //abc.com
                string stripaddress = "192.168.10.25";// ip address
                string bindinginfo = stripaddress + ":80:" + strhostname;

                //check if website name already exists in IIS
                Boolean bWebsite = IsWebsiteExists(strWebsitename);
            
                if (!bWebsite)
                {
                    Site mySite = serverMgr.Sites.Add(strWebsitename.ToString(), "http", bindinginfo, "C:\\inetpub\\TestApp");
                    mySite.ApplicationDefaults.ApplicationPoolName = strApplicationPool;
                    mySite.TraceFailedRequestsLogging.Enabled = true;
                    mySite.TraceFailedRequestsLogging.Directory = "C:\\inetpub\\Logging";
                    serverMgr.CommitChanges();
                   
                }
                else
                {
                    
                }
            }
            catch (Exception ae)
            {
                Response.Redirect(ae.Message);
            }
        } 

I want to create website like following picture in Server (another pc with IIS server) Image

Upvotes: 0

Views: 118

Answers (1)

Oscar
Oscar

Reputation: 13960

You need to tell to server manager that you want to manage a remote machine:

ServerManager serverMgr = ServerManager.OpenRemote("machineName");

Also, if running under VS, beware of run it as Administrator.

Upvotes: 1

Related Questions