Dynamic subdomains in asp.net mvc

后端 未结 3 1215
夕颜
夕颜 2020-12-28 21:30

I am fairly new to asp.net, and have little experience with iis. I would like to have each user of my application get their own sub-domain, but all use the same controllers.

3条回答
  •  星月不相逢
    2020-12-28 22:20

    Mostly not a problem. I think!

    In terms of the application/routing the routing starts where the domain ends so mapping multiple domains to the same application is not a problem, that will just work.

    In terms of IIS you can map as many domains as you want (well there's bound to be a limit) to a single site - I'm not sure if you can use a wildcard - what version of IIS are you using?

    When a request arrives there are events you can hook to look at the domain and hence set up parameters you want (user for example), the root URL for the request is available from the context later in the cycle too - but you'll want to pick it up early.

    If you can do wildcards it becomes fairly trivial - pick up the request, validate the subdomain against the users in the database (if not valid redirect to the default site), set the user and carry on through the normal routing.

    If you can't do wildcards then the challenge is adding host headers to the IIS application (website) on the fly from your application as users are added to the database.

提交回复
热议问题