.net - Using URL Rewrite on IIS to set response's Location header -
i have .net application (built outsystems platform) deployed on windows 2008r2, iis 7 environment. application working no problems. serving requests through https on port 443 , can access no problems.
now, there need enable users access through nat, configured serve requests on port 8200. requests forwarded server no problem, except when response redirect (http 302). in these cases, location header of response set port application being served port 443. when client's browser tries access url set in location header, fail since nat serving requests in port 8200.
in sum:
- client browser accesses
https://myserver:8200/myapp
; - nat translates url , forwards
https://myserver:443/myapp
; - application replies 302 redirect
https://myserver:443/redirect
; - client browser accesses
https://myserver:443/redirect
; - nat blocks access because expecting port 8200 ;
here tried do; installed url rewrite module in iis , created following rules:
- an inbound rule store request's host header (in these cases it's
https://myserver:8200
) server variable original_host. - an outbound rule replace host part of url sent in response's location header (
https://myserver:443/redirect
) value stored in server variable original_host. rule applied in case of redirect.
the problem facing minute enable rule, ajax requests stop working rule not apply them , when not accessing application through nat. when happens, seeing through ie's network tab in developer tools request header , body ok, response header ok, response body empty , should not be. also, if try debug ajax request @ server using breakpoint, not stopping @ breakpoint.
so, question: using url rewrite best way solve nat/url problem? if so, how can solve ajax situation? if not, how solve redirect problem?
*edit: here rule configuration:
thank in advance,
joão gomes
the simplest url rewrite want outbound rule targeting 3xx redirects. rule can parse location regex, , allow change port. i'm not sure if accomplishes setting out (if port must dynamic) should @ least way there.
the pattern (https?://[^:/]+):?([0-9]+)?(.*)
parse location follows:
https://sub.host.com:1337/foo/bar?query=true {r:1} => https://sub.host.com {r:2} => 1337 {r:3} => /foo/bar?query=true
note: if port not in url, {r:2}
empty.
then use case, reassemble in action rewrite to:
{r:1}:8200{r:3} => https://sub.host.com:8200/foo/bar?query=true
in web.config <system.webserver>
:
<rewrite> <outboundrules> <rule name="redirect port" precondition="3xx redirect"> <match servervariable="response_location" pattern="(https?://[^:/]+):?([0-9]+)?(.*)" /> <action type="rewrite" value="{r:1}:8200{r:3}" /> </rule> <preconditions> <precondition name="3xx redirect"> <add input="{response_status}" pattern="3[0-9][0-9]" /> </precondition> <precondition name="3xx redirect no query string"> <add input="{response_location}" pattern="^(.*)(\?.+)$" negate="true" /> <add input="{response_status}" pattern="3[0-9][0-9]" /> </precondition> <precondition name="3xx redirect query string"> <add input="{response_status}" pattern="3[0-9][0-9]" /> <add input="{response_location}" pattern="^(.*)(\?.+)$" /> </precondition> </preconditions> </outboundrules> </rewrite>
@hally9k - maybe looking also?
Comments
Post a Comment