8
votes

I have a self-hosted API running on port 8080. On port 80 is my web server (IIS 7.5) with a website I can't touch. I added an application "MyApiTestsite". Now all requests to /api/ or /signalr/ I would like to forward to port 8080:

http://mycompany/MyApiTestsite           -> untouched
http://mycompany/MyApiTestsite/signalr/* -> http://mycompany:8080/signalr/*
http://mycompany/MyApiTestsite/api/*     -> http://mycompany:8080/api/*

I already installed ARR (is this even necessary?) and URL Rewrite.

Here's my rule I have so far (for SignalR):

<rule name="Rewrite SignalR to port 8080" patternSyntax="Wildcard" stopProcessing="true">
  <match url="signalr/*" />
  <serverVariables>
    <set name="SERVER_PORT" value="8080" />
  </serverVariables>
  <action type="Rewrite" url="{R:0}" appendQueryString="true" logRewrittenUrl="false" />
</rule>

I checked the log-files and the rule gets matched. However, it doesn't work at all:

  • I don't know how to get rid of the RelativePath (my application) MyApiTestsite
  • If I check logs the port didn't get replaced

Log:

RULE_EVALUATION_END RuleName="Rewrite SignalR to port 8080", RequestURL="MyApiTestsite/signalr/hubs", QueryString="", StopProcessing="true", Succeeded="true"

URL_REWRITE_END RequestURL="/MyApiTestsite/signalr/hubs"

GENERAL_CHILD_REQUEST_START SiteId="4", RequestURL="http://mycompany:80/MyApiTestsite/signalr/hubs", RequestVerb="GET", RecursiveLevel="1"

Update: I now tried it according to this post. However, it still doesn't work. The URL seems good but the MvcHandler takes over and returns a 404:

URL_REWRITE_END RequestURL="http://mycompany:8080/signalr/hubs"

USER_SET AuthType="", UserName="", SupportsIsInRole="true"

HANDLER_CHANGED
OldHandlerName="ExtensionlessUrlHandler-Integrated-4.0", NewHandlerName="System.Web.Mvc.MvcHandler", NewHandlerModules="ManagedPipelineHandler", NewHandlerScriptProcessor="", NewHandlerType="System.Web.Mvc.MvcHandler, System.Web.Mvc, Version=5.1.0.0"

GENERAL_SEND_CUSTOM_ERROR HttpStatus="404", HttpSubStatus="4", FileNameOrURL="404.htm"

Update 2:

Here's a picture of what I want to do...

enter image description here

Update 3 This time I tried using Server Farms instead. My URL got changed as it's supposed to be but then it got changed back to the old URL:

ARR_WEBFARM_ROUTED WebFarm="mycompany API", Algorithm="LeastRequests"
HANDLER_CHANGED OldHandlerName="", NewHandlerName="ApplicationRequestRoutingHandler", NewHandlerModules="ApplicationRequestRouting", NewHandlerScriptProcessor="", NewHandlerType=""
ARR_SERVER_ROUTED RoutingReason="LoadBalancing", Server="mycompany", State="Active", TotalRequests="1", FailedRequests="0", CurrentRequests="1", BytesSent="0", BytesReceived="0", ResponseTime="0"
GENERAL_SET_REQUEST_HEADER HeaderName="Max-Forwards", HeaderValue="10", Replace="true"
GENERAL_SET_REQUEST_HEADER HeaderName="X-Forwarded-For", HeaderValue="xxx.xx.xx.xxx:52327", Replace="true"
GENERAL_SET_REQUEST_HEADER HeaderName="X-ARR-SSL", HeaderValue="", Replace="true"
GENERAL_SET_REQUEST_HEADER HeaderName="X-ARR-ClientCert", HeaderValue="", Replace="true"
GENERAL_SET_REQUEST_HEADER HeaderName="X-ARR-LOG-ID", HeaderValue="f8exxxc2-7a6d-4cf6-a3c6-ecde245a0d80", Replace="true"
GENERAL_SET_REQUEST_HEADER HeaderName="Connection", HeaderValue="", Replace="true"
//>>>>>now it gets changed back!!! Why????<<<<<<
URL_CHANGED OldUrl="http://mycompany API/signalr/hubs", NewUrl="/MyApiTestsite/signalr/hubs"
2
Is your IIS configured correcyly? see asp.net/signalr/overview/signalr-20/… for exact spesificaitonsShachaf.Gortler
Let's put it this way: If I hardcode the API/SignalR access on port 8080 and use CORS then everything works as expected. However, I would like to hide this information from the user.Dunken
ARR should not be necessary, just URL Rewrite.Brock Hensley
I'm having the same problem. The (correctly) rewritten URL gets hijacked and reverted back to its original value. It appears to be an incompatibility between URL Rewrite/ARR and MVC.PrgTrdr

2 Answers

0
votes

Configure the following URL Rewrite rule:

Requested URL: Matches the pattern
Using: Regular Expressions
Pattern: MyApiTestsite/(signalr/.*)
Action: Rewrite
Rewrite URL: http://mycompany:8080/{R:1}

EDIT: {R:1} matches the 1st captured regexp group in this case what matches (signalr/.*). If it was {R:0} instead, it would have put the whole relative URL that was matched. See IIS URL Rewrite {R:N} clarification for more info.

0
votes

Try this: This works!

<rewrite>
        <rewriteMaps>
            <rewriteMap name="root">
                <add key="/root/" value="/" />
            </rewriteMap>
        </rewriteMaps>
        <rules>
            <clear />
            <rule name="MyRedirect" stopProcessing="true">
                <match url="^MYApiTestsite/(api|signalr)(/.*)?" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="Redirect" url="http://mycompany:8080/{R:1}{R:2}" />
            </rule>
        </rules>
    </rewrite>

If you want to use GUI then enter image description here