iis cname to subdomain, get subdomain from the request

点点圈 提交于 2020-01-26 04:21:08

问题


What I'd really like to do is set up an azure site called site.com. Then have hundreds of subdomains such as foo.site.com, bar.site.com, baz.site.com etc. My asp.net mvc application will pull out the subdomain as this will be used as an identifier. Next I'd like to have other domains CNamed to the subdomains. Such as hello.othersite.com -> foo.site.com, so that the browser still shows hello.othersite.com but I'd be able to get the foo subdomain out of the request.

I don't want to have to configure any of this because there are going to be lots of subdomains, essentially one per account.

Is this actually possible?

I've tried a few tests but I'm not 100% sure how to proceed. Would I just:

  1. Setup site.com to accept *.site.com
  2. CNAME hello.othersite.com to foo.site.com (do I want masking, forwarding etc?)
  3. Does the incoming http request contain any information about the subdomain (foo) that it's CNAMED to?

I hope this isn't too vague and hand wavey but some confirmation of its plausibility would be a great help.


回答1:


It is not just Azure, but the whole web.

I don't think it is possible to get out of the HTTP request for hello.othersite.com that it actually mapped in the DNS to foo.site.com. And this is because your actual HTTP request will look something like

GET /index.html HTTP/1.1
(other headers)
host: hello.othersite.com

Your web server, whatever it is, has no idea that hello.othersites.com is mapped via CNAME to foo.site.com. The request you receive is for hello.othersite.com.

If you do forwarding, the users will never stay on hello.othersite.com but will be redirected to foo.site.com. I guess this is not what you want.

Direct domain masking is usually done via iFrame, which would also not recommend.

I would do the following, as nothing else comes to mind at the moment:

  1. Setup the site to accept *.site.com and *.othersite.com
  2. Add Wildcard CNAME map to my Azure cloud service, i.e. *.site.com -> CNAME -> my.cloudapp.net. Same for both custom domains I want to have.
  3. Perform necessary checks in my app to figure out domain mappings <-> user accounts.


来源:https://stackoverflow.com/questions/13874053/iis-cname-to-subdomain-get-subdomain-from-the-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!