2013-12-11 39 views
0

道歉如果标题不清楚,基本上我有一个Web代理侦听端口80,并在IIS上设置了URL重写(web.config上的规则为8095直接如何识别请求是否来自URL重写模块

,但我也想成为: - 以下),但它确实

http://example.com/api/blah/blah>
http://example.com:8095/api/blah/blah

<rule name="api-example" enabled="true" patternSyntax="ECMAScript" stopProcessing="true"> 
    <match url="^.*/api/.*$" /> 
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" /> 
    <action type="Rewrite" url="http://localhost:8095/{R:0}" appendQueryString="true" logRewrittenUrl="false" /> 
    </rule> 

它工作得很好,没有任何问题,也当我请求本地主机的工作原理能够识别请求是直接请求还是通过URL重写模块。

我的想法是,在查询字符串添加到URL,当URL大干快上IIS rewrited,这样我可以检查,如果再查询字符串存在,它是通过URL重写,如果没有,那么这是一个直接请求

例子:

http://example.com/api/blah/blah?from=proxy - > http://example.com:8095/api/blah/blah?from=proxy

http://example.com/api/blah/blah?existing_query_string=blah&from=proxy - > http://example.com:8095/api/blah/blah?existing_query_string=blah&from=proxy

如何ç我做到了这一点?或者还有其他方法可以做到吗?

非常感谢

回答

0

您可以尝试访问

Request.ServerVariables["HTTP_X_ORIGINAL_URL"] 

,并把它比作Request.Url.PathAndQuery。或者,

Request.RawUrl 

还应该包含原始URL。

+0

您好我进行了尝试,并HTTP_X_ORIGINAL_URL节目我只在url重写前的原始路径和查询字符串,但没有域值,这将无济于事,如果我转发到另一个Web服务器具有完全相同的路径和查询字符串。原始网址根本没有帮助。 – Ming

1

我最终去了我自己的解决方案,这是IIS添加一个查询字符串url重写 和Url重写模块足够聪明以追加查询字符串arr = 1到网址无关紧要的url是否有已经有查询字符串,

然后我添加代码来检查查询字符串中包含ARR = 1或不是,如果有,则请求来通过URL重写

<rule name="api-example" enabled="true" patternSyntax="ECMAScript" stopProcessing="true"> 
    <match url="^.*/api/.*$" /> 
     <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{QUERY_STRING}" pattern="(.*)" negate="false" /> 
     </conditions> 
    <action type="Rewrite" url="http://localhost:8095/{R:0}?arr=1" appendQueryString="true" logRewrittenUrl="false" /> 
    </rule>