3

I have the same problem as in the referenced post (Rewrite rule for WebAPI fails because of ExtensionlessUrlHandler) and have tried several attempts to workaround the issue with some success. What I am stuck at now is the following:

Background:

  • IIS7, Rewrite Module and ARR (I am a newbie to rewrite & ARR)
  • Site1 hosting my web front using ASP.Net MVC4 (www.foo.com)
  • Site2 hosting my webapi using ASP.Net MVC4 (svc.foo.com)
  • I have full control over the code & site configs for both sites

Goal:

  • rewrite www.foo.com/svc/* to svc.foo.com/api/*

Working:

  • www.foo.com/svc/somecontroller/0 successfully maps to svc.foo.com/api/somecontroller/0

Not Working:

  • www.foo.com/svc/somecontroller?id=0
  • I turned on Failed Request Tracking and it seems the rewrite module is rewritting the url but for some reason the request is never made to svc.foo.com

Details:

  • To workaround the issue in the referenced post I append a ".s" to the end of every call to a webapi (I have full control so I can do this - not ideal but I need this working so okay for now)
  • Without QS: www.foo.com/svc/somecontroller/0 becomes www.foo.com/svc/somecontroller.s
  • With QS: www.foo.com/svc/somecontroller?id=0 becomes www.foo.com/svc/somecontroller?id=0.s
  • I then use rewrite rules to strip the ".s" and make the real call to svc.foo.com/api/somecontroller/0 or svc.foo.com/api/somecontroller?id=0

I can't for the life of me figure out why when the querystring format is used this doesn't work.

Rewrite Rules:

< rule name="Route requests with QS" stopProcessing="true">
    < match url="^svc/(.*)" />
    < conditions>
        < add input="{QUERY_STRING}" pattern="(.*).s" />
    < / conditions>
    < action type="Rewrite" url="http://svc.foo.com/api/{R:1}?{C:1}" appendQueryString="false" logRewrittenUrl="true" />
< / rule>
< rule name="Route the requests without QS" stopProcessing="true"> 
    < match url="^svc/(.*).s" /> 
    < conditions>
        < add input="{CACHE_URL}" pattern="^(https?)://" /> 
    < / conditions> 
    < action type="Rewrite" url="{C:1}://svc.foo.com/api/{R:1}" logRewrittenUrl="true" /> 
< / rule>

Thanks in advance!

2
  • Did you ever find a solution? I wanted to do the same thing Commented Aug 15, 2013 at 13:47
  • Would it be because the /0.s would be considered an extension while ?0.s is not an extension? therefore it goes through the extensionlessUrlHandler and fails as in referenced post? Commented Aug 15, 2013 at 13:55

1 Answer 1

0

This post worked for me. ARR/URL Rewriter within a .net Web API application

Adding the ignoreRoutes did the job perfectly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.