na3Er-faraji
na3Er-faraji

Reputation: 96

how to create sub-domains

i am going to create some sub-domains on my website. when i create a sub-domain i must define a directory that sub-domain will refer to newly created sub-domain. but i want a different solution.

i want to detect when a user enters a URL , which sub-domain is used and then do some operation for each special sub-domain. for example if website user entered a.mysite.com i extract "a" sub-domain from URL and then without redirecting webpage i load some data in page.

please help me how i do these,on both web-server and localhost?

Upvotes: 1

Views: 246

Answers (1)

philipproplesch
philipproplesch

Reputation: 2127

In general your application doesn't care about the host name, so you have to configure your IIS to handle all requests.

  • Production only: Create a wildcard DNS record for your domain (e.g. *.domain.tld)
  • Your IIS site should have no explicit bindings, so that ALL incoming requests hit this application (other sites should still work fine!).

After this you can check the HttpContext.Current.Request.Url and extract the requested subdomain.

Upvotes: 1

Related Questions