[英]How to configure IIS application to work as a gateway
I have written an ASP.NET Web API which is basically an API gateway. 我写了一个ASP.NET Web API,它基本上是一个API网关。 The base URL of the gateway is
http://localhost:88/ApiGateway
. 网关的基本URL是
http://localhost:88/ApiGateway
。 The service I have implemented looks up some header values and cookies in order to route a request. 我实现的服务会查找一些标头值和cookie,以路由请求。 Currently I use it for blue-green deployments.
目前,我将其用于蓝绿色部署。
When a header or cookie with a specific API-ID is found, the request is routed to the corresponding API. 找到具有特定API-ID的标头或cookie时,该请求将路由到相应的API。
For example, if the found API-ID is alpha-v1.7.4
, and the URL is http://localhost:88/gateway/app/login.html
, the request is routed to http://localhost:8080/app/alpha-v1.7.4/app/login.html
where the actual app or website resides. 例如,如果找到的API-ID是
alpha-v1.7.4
,并且URL是http://localhost:88/gateway/app/login.html
,则请求将路由到http://localhost:8080/app/alpha-v1.7.4/app/login.html
实际应用程序或网站所在的位置。
This work perfectly when using OWIN and Katana. 当使用OWIN和Katana时,这完美地工作。 All URLs are routed correctly.
所有网址均正确路由。
When installing the gateway in IIS, things are getting strange. 在IIS中安装网关时,事情变得很奇怪。
I have put a very verbose logging into the gateway which logs each request and the found route. 我已经将非常详细的日志记录到网关中,该日志记录了每个请求和找到的路由。 On IIS I observe that the followings requests are reaching the gateway and are routed properly:
在IIS上,我观察到以下请求已到达网关并正确路由:
1: http://localhost:88/gateway/app/some_directory/
2: http://localhost:88/gateway/app/another_directory_with_a.dot/
3: http://localhost:88/gateway/app/some_path_no_trailing_slash
The following request do not reach the gateway: 以下请求未到达网关:
4: http://localhost:88/gateway/app/no_trailing_slash_with_a.dot
5: http://localhost:88/gateway/app/index.html
To me it seems that IIS is letting pass any directory paths (ie with a trainling slash like .../.../directory/
), all resource path (ie with no trailing slash like .../.../resource
) which do not smell like a file (since they have not dot), but blocks paths which have no trailing slash but a dot inside ( .../.../may_be_a.file
is blocked, but .../.../not_a.file/
passes). 在我看来,IIS允许传递任何目录路径(即带有
.../.../directory/
的训练斜杠)和所有资源路径(即不带有.../.../resource
尾随斜杠) )闻起来不像文件(因为它们没有点),但是阻止了没有尾部斜杠但内部有点的路径( .../.../may_be_a.file
被阻止,但是.../.../not_a.file/
通过)。
Following these instruction did not work for me: How to disable Request Filtering for a specific website on IIS 7.5? 遵循以下说明对我不起作用: 如何在IIS 7.5上为特定网站禁用请求筛选?
Any idea how to configure IIS to get this to work? 任何想法如何配置IIS以使其正常工作?
After messing around with RAMMFAR which did not work for me, I came around with this solution: 在弄乱了对我不起作用的RAMMFAR之后,我想到了这个解决方案:
<system.webServer>
<handlers>
<clear />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
Just clearing all handlers and adding the one and only I need solved the problem. 只需清除所有处理程序并添加一个处理程序,就可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.