[英]How to work with mulitple domains in a single app? ASP.net core 3.0 (razor pages, azure)
I am expanding my website to another country.我正在将我的网站扩展到另一个国家。 It's basically a listing of events.
它基本上是一个事件列表。
I'd like to only show events from belgium if domain is {companyname}.be, only events from the netherlands if {companyname}.nl etc.如果域是 {companyname}.be,我只想显示来自比利时的事件,如果是 {companyname}.nl 等,则只显示来自荷兰的事件。
To keep the costs down I want this to work in a single azure web app, so I'd need to get the domain name from the request since I cannot set this in configuration.为了降低成本,我希望它在单个 azure web 应用程序中工作,所以我需要从请求中获取域名,因为我无法在配置中设置它。
I know i can get the current domain by using我知道我可以通过使用获取当前域
HttpContext.Current.Request.Url.Host
But I feel I'm missing some "best practice" approach.但我觉得我错过了一些“最佳实践”的方法。 Something that would also work in development and preproduction environments.. any documentation you know of that could help me out?
在开发和预生产环境中也可以使用的东西..您知道的任何文档都可以帮助我吗?
UPDATE更新
I have mapped multiple custom domains to my web app.我已将多个自定义域映射到我的 web 应用程序。 It works well, the result as below.
它运行良好,结果如下。
PRIVIOUS私人的
we also can use second-level domain names to fulfill your needs.我们也可以使用二级域名来满足您的需求。 You can use
be.websitename.com
to access on behalf of Belgian users.您可以使用
be.websitename.com
代表比利时用户访问。
//Home/getUrl
public IActionResult getUrl() {
string url = HttpContext.Request.Host.Value;
return Content(url);
}
You can set your second-level domain in your portal.您可以在门户中设置您的二级域。 Like pic.
喜欢图片。
Then you can test it by broswer.然后你可以通过broswer测试它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.