8

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"
Dunken
  • 8,481
  • 7
  • 54
  • 87
  • 1
    Is your IIS configured correcyly? see http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/supported-platforms for exact spesificaitons – Shachaf.Gortler Apr 28 '14 at 10:34
  • 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 Apr 28 '14 at 10:45
  • ARR should not be necessary, just URL Rewrite. – Brock Hensley Apr 28 '14 at 16:01
  • 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 Jun 20 '14 at 15:58

2 Answers2

0

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.

Community
  • 1
  • 1
Zlatin Zlatev
  • 3,034
  • 1
  • 24
  • 32
  • Thanks. However, I don't think my rule is wrong as it gets applied. Question is why does it get changed back... – Dunken May 13 '14 at 07:42
  • Technically your rule is not wrong, but it does not do what you want - e.g. to remove the MyApiTestsite from the URL. The rule I suggested to you should do that. – Zlatin Zlatev May 13 '14 at 07:58
  • Also my suggestion is related to use of simple URL Rewrite. I do not think you need Server Farms at all for the setup you are intending. – Zlatin Zlatev May 13 '14 at 08:10
0

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

zman
  • 189
  • 2
  • 9