2

I know next to nothing about configuring IIS, but have been assigned a task to add a query variable to every request that is made through an IIS server that's being used as a Web proxy.

We look for any URL where the first path segment after the domain is a fixed string, like /bongo/ and redirect that to a back end server. I have it working to perform redirects, but I'm pretty sure I have a lot of garbage that I don't need in the following config, which I got from another answer.

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
        <rewrite> 
            <rules> 
                <rule name="Route the requests for bongo Player" stopProcessing="true"> 
                    <match url="^bongo/(.*)" /> 
                    <conditions> 
                        <add input="{CACHE_URL}" pattern="^(https?)://" /> 
                    </conditions> 
                    <action type="Rewrite" url="https://bongo.fse.companyinc.com/bongo/{R:1}" /> 
                    <serverVariables> 
                        <set name="HTTP_ACCEPT_ENCODING" value="" /> 
                    </serverVariables> 
                </rule> 
            </rules> 
            <outboundRules> 
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1"> 
                    <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://bongo.fse.companyinc.com/bongo/(.*)" /> 
                    <action type="Rewrite" value="/{R:2}" /> 
                </rule> 
                <rule name="RewriteRelativePaths" preCondition="ResponseIsHtml1"> 
                    <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/bongo/(.*)" negate="false" /> 
                    <action type="Rewrite" value="/{R:1}" /> 
                </rule> 
                <preConditions> 
                    <preCondition name="ResponseIsHtml1"> 
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" /> 
                    </preCondition> 
                </preConditions> 
            </outboundRules> 
        </rewrite>
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="ASP" verbosity="Verbose" />
                        <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
                        <add provider="ISAPI Extension" verbosity="Verbose" />
                        <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket,Rewrite,RequestRouting" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions timeTaken="00:00:30" statusCodes="200-299,300-399,400-499,500-599" verbosity="Warning" />
                </add>
            </traceFailedRequests>
        </tracing> 
    </system.webServer> 
</configuration>

1) I'm not even sure that I need the outbound rules.

2) The main problem that I have is that I want to always append a query variable, whether there are existing query variables or not. I've tried too many configurations to list here, but I can't seem to always get it to append the variable when proxying. Also, I think there needs to be some sort of conditional that does something different if there are already arguments or if the one to be added is the only one.

I'd appreciate help from any IIS gurus out there.

2
  • Actually, solved this. It was a piece of cake. The issue is that we assumed that IIS would append the existing query string so we tried: <action type="Rewrite" url="https://bingo.lms.bingoinc.com/bingo/{R:1}&abc=asd23242" /> In fact, it's smart enough to check if there is already a '?' and adds original query variables to the end, so this works: ` <action type="Rewrite" url="bingo.lms.bingoinc.com/bingo{R:1}?abc=asd23242" />`
    – r b
    Apr 18, 2018 at 20:41
  • Post that as an answer and accept it.
    – Lex Li
    Apr 18, 2018 at 20:56

1 Answer 1

0

Actually, solved this. It was a piece of cake. The issue is that we assumed that IIS would append the existing query string so we tried:

<action type="Rewrite" url="https://bingo.lms.bingoinc.com/bingo/{R:1}&abc=asd23242" /> 

In fact, it's smart enough to check if there is already a '?' and adds original query variables to the end, so this works:

<action type="Rewrite" url="bingo.lms.bingoinc.com/bingo{R:1}?abc=asd23242" />

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .