Recently the Department to develop a simple app, part of the data is existing projects already exist, in order to facilitate maintenance, want to provide only an interactive portal, and the rules of the agreement will not change.
Based on this requirement, there are two sets of solutions:
1. Use the code to encapsulate the existing API layer, the request data and return data do not make any changes, just transit, and then deployed in a project with the new data interface;
2. Request forwarding with IIS, call the existing interface response request, the remainder of the development of new APIs, deployed in a project, with URL rewrite for filtering distribution.
The first scenario is traditional, there is nothing to evaluate, here is the implementation of the second scenario, the advantage of the second scenario is that you can save time costs and rely on the IIS plug-in (application Request Routing + URL Rewrite).
Download arr and URL Rewrite for installation, using the process to discover that ARR is dependent on the IIS Directory browsing feature (not verified, if it is not available, you can see if the Directory browsing feature is installed):
Http://www.iis.net/downloads/microsoft/application-request-routing#additionalDownloads
Http://www.iis.net/downloads/microsoft/url-rewrite#additionalDownloads
Install the plugin and reopen IIS
Double-click the IIS root directory
Double-click Application Request Routing Cache
Double-click on the right Server Proxy Settings
Tick the Enable proxy
After clicking "Apply", create a new site to accept the request for forwarding
Double-click Site, double-click URL Rewrite, ADD rules (new rule), blank rule (blank rules)
Name: Fill in your rule names
The match URL is a rule that matches the requested URL
Http://www.test.com?name=michael&age=30
host: www.test.com
requested URL:? name=michael&age=30
query string: name=michael&age=30
Requested URL selection Matches the Pattern (matches the URL of the rule)
Using Select Regular Expressions (use regular expressions to match)
The Pattern filled in ^ (. *) here does not explain the regular expression, it is necessary to understand their own.
Tick Ignore case ignoring casing
Expand Conditions Conditional filtering
Logical Grouping Select Match any
Match all is the list in which all rules are matched to match (with)
Match any is a rule match in the list even if it matches (or)
Track capture group across conditions tracking capture groups, this function is related to the regular, there is no need to uncheck, you can query the keyword capture group to learn more
Add a condition by clicking Add
Condition input Fill in {http_host} , Http_host represents the request head of the HOST, is the www.test.com part of the above example, more filters to query Server Variables self Solution
Check if input string select Matches the Pattern
Pattern fill ^arrtest.com$ , here means if host is arrtest.com then match by example: http://arrtest.com?asdf=1234
If the ^www.arrtest.com$ is filled in here, then match http://www.arrtest.com?asdf=1234
Tick Ignore case ignoring casing
Double-click the Expand Action section
Action type Select Rewrite rewrite forward
Rewrite URL to fill in https://cn.bing.com/{r:1} Forwarding Destination address {r:1} represents the match URL part matching Request URL
Tick Append query string to append queries
By the end of this configuration, saving this rule, accessing the http://arrtest.com/search?q= test in the browser is equivalent to accessing the https://cn.bing.com/search?q= test
To prevent other interfaces under this site from being forwarded without a brain, we need to add a forwarding condition
The existing API formats that need to be forwarded are as follows http://arrtest.com?PROTOID=123456
The other interface is not protoid this keyword, and protoid after the value is a number, then this keyword to filter the need to forward the request
Go back to just the Conditions section, click Add New Condition
Condition input to fill in {query_string}
Check if input string select Matches the Pattern
Pattern fill in protoid=\d+ This rule means that the match query string is protoid the request that starts the parameter value as a number (example: http://arrtest.com/?PROTOID=456789)
Tick Ignore case ignoring casing
OK save, modify match logic to match all (with), all the rules in the list are matched, the request will pass
Now only the request that QueryString for protoid starts with a numeric value will be forwarded.
Example: http://arrtest.com/search?PROTOID=4564&q= test = http://cn.bing.com/search?PROTOID=4564&q= Test
http://arrtest.com/search?q= Test &protoid=4564 will not be forwarded
The ability to request forwarding is implemented, and the powerful ARR + URL Rewrite also enables high-availability load balancing .
Implementing request Forwarding with IIS