简体   繁体   中英

Redirect multiple domains to same azure website with custom parameters

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

  • 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 eg " 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.

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

  1. Are you going to place code directly on the customers website to
    redirect?
  2. Do you have the access to the customers DNS's allowing you to forward their site to mywebsite.azurewebsites.net?
  3. Do you want to create a CNAME record and point it to your Azure Website?

Method #1

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

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

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.

Method #2

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.

Method #3

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.

The specific code is here:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM