使用自定义参数将多个域重定向到相同的azure网站 [英] Redirect multiple domains to same azure website with custom parameters

查看:258
本文介绍了使用自定义参数将多个域重定向到相同的azure网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,我有一个将被多个客户使用的网站。
但我不想将网站发布到每个客户域名。相反,我会将网站发布到一个天蓝色的网站,例如 mywebsite.azurewebsites.net ,我希望所有客户域重定向到 mywebsite.azurewebsites.net ,但我需要知道这是哪个客户,这样我才能显示正确的内容。例如,我正在考虑在查询字符串中附加或发送隐藏的自定义参数等。
我需要知道的是

I have a scenario where I have a web site that will be used by multiple customers. But I do not want to publish the web site to each customer domain's. Instead I will publish the web site to an azure web site for example mywebsite.azurewebsites.net and I want all the customers domains to redirect to this mywebsite.azurewebsites.net but I need to know which customer is this so I can display the correct content. for example I am thinking about appending or sending a hidden custom parameter in the query string or such. What I need to know is


  • 如何将所有域重定向到 mywebsite.azurewebsites.net

  • 如何在重定向中传递隐藏参数,例如来自客户域的任何请求,例如 www.cust1.com/Home/Index 将被重定向到 mywebsite.azurewebsites.net/Home/Index?username=testuser www.cust1.com/Home/Index?querystring=ffff mywebsite.azurewebsites.net?querystring=ffff&username=testuser

  • 我不想在客户网站上发布任何网站内容客户域根目录将为空。

  • How can I redirect all the domains to mywebsite.azurewebsites.net
  • How can I pass a hidden parameters in the redirect for example any request from the customer domain e.g "www.cust1.com/Home/Index" will be redirected to "mywebsite.azurewebsites.net/Home/Index?username=testuser" and "www.cust1.com/Home/Index?querystring=ffff" to "mywebsite.azurewebsites.net?querystring=ffff&username=testuser"
  • I do not want to publish any web site content on the customer web site that means the customer domain root directory will be empty.

推荐答案

您有很多不同的方法可以做到这一点。

There are quite a few different ways you can do this.

您需要确定的第一件事是:您将如何处理重定向到mywebsite.azurewebsites.net

The first thing you need to determine is: How are you going to handle the redirection to mywebsite.azurewebsites.net?


  1. 您是否要将代码直接放在客户网站上以进行
    重定向?

  2. 您是否可以访问客户DNS,允许您将其网站转发到mywebsite.azurewebsites.net?

  3. 您是否要创建CNAME记录并将其指向Azure网站?

方法#1

如果你有访问客户网站,这将成为最简单的方法。

If you have access to the customers website then this becomes the easiest method.

如上所述,我只是将用户重定向回某个类型的自定义网址,即mywebsite.azurewebsites.net/customer1。

As you described above, I would simply redirect the user back to your site with some type of custom url i.e mywebsite.azurewebsites.net/customer1 .

当用户点击此页面时,您可以在浏览器中设置一个cookie,以便您知道它们来自何处,然后将它们重定向到mywebsite.azurewebsites的主页。净。这几乎会立即发生,客户永远不会注意到。

When the user hits this page you could then set a cookie in their browser so that you know where they came from and then redirect them to the home page at mywebsite.azurewebsites.net. This would happen almost instantly and the customer would never notice.

方法#2

如果您能转发域名或他们只能将用户重定向到mywebsite.azurewebsites.net的主网站,您可以在请求进入时简单查找引用网址。然后,如上所述,根据引用网址,您可以设置您的Cookie并显示适当的内容。

If you are able to forward the domain or they can only redirect the user to the main website at mywebsite.azurewebsites.net, you can simple look for the referring url when the request comes in. Then as you do above, based on the referring URL you can then set your cookie and show the proper content.

方法#3

这是假设您有权访问客户DNS记录并能够为www.customerwebsite.com创建CNAME记录 - > mywebsite.azurewesbites.net

This is assuming you have access to the customers DNS records and are able to create a CNAME record for www.customerwebsite.com -> mywebsite.azurewesbites.net

在这种情况下,当用户访问该网站时,您只需下拉主机,然后根据它设置您的内容。

In that case, when the user visits the site you would just pull down the HOST and then set your content based on that.

具体代码如下:

string url = HttpContext.Current.Request.Url.AbsoluteUri;
// http://localhost:1302/TESTERS/Default6.aspx

string path = HttpContext.Current.Request.Url.AbsolutePath;
// /TESTERS/Default6.aspx

string host = HttpContext.Current.Request.Url.Host;
// localhost

您可以在此处找到更多信息:如何在C#中获取当前页面的URL

You can find more information here: How to get the URL of the current page in C#

如果您有任何疑问或最终实施任何这些解决方案,请与我们联系。

Let me know if you have any questions or end up implementing any of these solutions.

这篇关于使用自定义参数将多个域重定向到相同的azure网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆