Mertez
Mertez

Reputation: 1131

How can I create subdomains programmatically in ASP.NET?

Is there any way to create subdomains via code and route them to my main domain?

product123.domain.com instead of www.domain.com/products/?id=123

Upvotes: 5

Views: 1869

Answers (1)

mellodev
mellodev

Reputation: 1607

We do the same thing, but do not generate the DNS records with code. Instead we create a wildcard DNS entry, resolving all subdomains to a given IP. Inside code, we retreive the subdomain from the request URI and use it for further processing.

We use Route53 DNS by amazon, and have an A entry like this

*.ourblogsite.com 184.5.5.5

Which resolves all subdomains to that IP address. Inside IIS we bind an application to port 80 of that IP rather than hostname, which will handle any requests. The Web application is an MVC application, which breaks apart the request URI and fishes the subdomain portion out. We use this to power the somename.ourblogsite.com functionality, where somename is a unique identifier given by the client.

Upvotes: 8

Related Questions