IIS7 asp.net MVC的WebAPI重写 [英] iis7 asp.net mvc webapi rewrite

查看:366
本文介绍了IIS7 asp.net MVC的WebAPI重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有同样的问题,因为在引用后(<一个href=\"http://stackoverflow.com/questions/13885343/rewrite-rule-for-webapi-fails-because-of-extensionlessurlhandler\">Rewrite为的WebAPI规则失败,因为ExtensionlessUrlHandler ),并曾试图多次尝试取得了一些成功要解决的问题。什么我坚持在现在是这样的:

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:

背景:


  • IIS7,重写模块和ARR(我是新手改写&安培; ARR)

  • 站点1主机使用ASP.Net MVC4我的web前端(www.foo.com)

  • 站点2主机使用ASP.Net MVC4我的WebAPI(svc.foo.com)

  • 我有超过code和完全控制;网站CONFIGS为这两个网站

目标:


  • 重写www.foo.com/svc/*到svc.foo.com/api~~V / *

工作


  • www.foo.com/svc/somecontroller/0~~MD成功映射到svc.foo.com/api/somecontroller/0~~V

不工作:


  • www.foo.com/svc/somecontroller?id=0

  • 我打开失败请求跟踪,似乎重写模块rewritting的URL,但由于某种原因,请求从不svc.foo.com取得

详细内容:


  • 要解决该问题,引用的文章中,我添加一个.S的每一个通话结束到的WebAPI(我有完全的控制,所以我可以做到这一点 - 不理想,但我需要这方面的工作这么好了)

  • 无QS:www.foo.com/svc/somecontroller/0成为www.foo.com/svc/somecontroller.s

  • 通过QS:www.foo.com/svc/somecontroller?id=0成为www.foo.com/svc/somecontroller?id=0.s

  • 我然后使用重写规则剥夺了.S,并真正调用svc.foo.com/api/somecontroller/0~~V或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.

重写规则:

< 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>

在此先感谢!

推荐答案

本岗位为我工作。
<一href=\"http://stackoverflow.com/questions/21667270/arr-url-rewriter-within-a-net-web-api-application?lq=1\">ARR/URL一个的.NET Web API应用内重写

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

添加ignoreRoutes做的工作非常完美。

Adding the ignoreRoutes did the job perfectly.

这篇关于IIS7 asp.net MVC的WebAPI重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆