In this article, I will tell you how to configure DNS record for sub domain.
Step 1
Open your domain control panel then go to DNS manager.
Step 2
Add following A records for domain.com and www.domain.com which point to IIS server IP address:
domain.com IN A XXX.XXX.XXX.XXX
www.domain.com IN A XXX.XXX.XXX.XXX
service.domain.com IN A XXX.XXX.XXX.XXX
First two rows will ensure that whenever user browse domain.com or www.domain.com at that time it will be routed to IIS server and rest will be take care by IIS then it will serve public site. The third row in above is important for next step.
Step 3
Now add following wildcard CNAME record:
*.domain.com IN CNAME service.domain.com
In above wildcard entry ensure that any sub domain request for domain.com will be routed to server which is pointed by service.domain.com.
In IIS setup, you have to edit website binding to include domain.com and www.domain.com as host header, by this way you can tell IIS that any request from domain.com and www.domain.com will be handled by this particular website. So, whenever user browse domain.com or www.domain.com it is serving public website without any problem.
While in case of sub domain it is showing error that “The connection was reset” this is because IIS does not found host header entry for requested domain in any websites. So, you need to add host header entry in service.domain.com website created in IIS setup because service.domain.com is actual website which is going to serve hosted service application when it is browse from sub domain. Use the following code to add host header entry programmatically in IIS:
private string GetWebSiteId(string serverName, string websiteName)
{
string result = "-1";
DirectoryEntry w3svc = new DirectoryEntry(string.Format("IIS://{0}/w3svc", serverName));
foreach (DirectoryEntry site in w3svc.Children)
{
if (site.Properties["ServerComment"] != null)
{
if (site.Properties["ServerComment"].Value != null)
{
if (string.Compare(site.Properties["ServerComment"].Value.ToString(),
websiteName, true) == 0)
{
result = site.Name;
break;
}
}
}
}
return result;
}
private void AddHostHeader(string hostHeader, string websiteID)
{
DirectoryEntry site = new DirectoryEntry("IIS://localhost/w3svc/" + websiteID);
PropertyValueCollection serverBindings = site.Properties["ServerBindings"];
serverBindings.Add(hostHeader);
Object[] newList = new Object[serverBindings.Count];
serverBindings.CopyTo(newList, 0);
site.Properties["ServerBindings"].Value = newList;
site.CommitChanges();
}
AddHostHeader("127.0.0.1:80:user1.domain.com", GetWebSiteId("localhost", "service.domain.com"));
HostForLIFE.eu IIS 8.0 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.