Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create subdomain per user

How is it possible to create a subdomain for each registered user of the web-site during the registration?
For the scenario below...

  1. User opens site.com/register.
  2. Provides details and submits.
  3. Gets redirected to the newuser.site.com straight away
  4. User can work in the newuser.site.com area

I don't know how to solve the issues:

  1. Create and propagate a subdomain for the user.
  2. Have the single ASP.NET application to handle all subdomains and the main domain.
  3. Configuraton of IIS.

Ideally I would like to stay withing .NET Framework as much as possible.

like image 451
Dmytrii Nagirniak Avatar asked Jan 29 '26 03:01

Dmytrii Nagirniak


1 Answers

You might approach it like this:

  1. First, establish a wildcard DNS domain (*) for your site's IP address. That will allow anystring.yourdomain.com to resolve correctly.
  2. Configure IIS to bind to a dedicated IP address, but not to rely on host headers (have an empty host header). That will cause all HTTP requests for the bound IP to be directed to your site.
  3. Have an HttpModule that looks at the incoming domain (in HttpContext), and rejects it if it's not valid. You might consider setting a cookie or ticket or something like that, to avoid the need to do a DB lookup for each request in order to validate it.
like image 136
RickNZ Avatar answered Jan 31 '26 15:01

RickNZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!