Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net IIS 7中域名的URL重写_Asp.net_Iis 7.5_Rewrite - Fatal编程技术网

Asp.net IIS 7中域名的URL重写

Asp.net IIS 7中域名的URL重写,asp.net,iis-7.5,rewrite,Asp.net,Iis 7.5,Rewrite,我在IIS中有两个asp.net站点:api.mydomain.com和mobileapi.mydomain.com。对api的一些请求应该重写为mobileapi。我不能让它工作。从我的实验来看,似乎我不能用rewrite重写url的域名部分。如果我改为重定向,除了我想要重写而不是重定向之外,所有的事情都可以工作 但是,如果我改为重定向到同一个域上的某个对象,假设我将操作url交换到/testing/{R:0}而不使用任何域名,那么它将按预期工作,并且重写得很好 我的web.config &l

我在IIS中有两个asp.net站点:api.mydomain.com和mobileapi.mydomain.com。对api的一些请求应该重写为mobileapi。我不能让它工作。从我的实验来看,似乎我不能用rewrite重写url的域名部分。如果我改为重定向,除了我想要重写而不是重定向之外,所有的事情都可以工作

但是,如果我改为重定向到同一个域上的某个对象,假设我将操作url交换到/testing/{R:0}而不使用任何域名,那么它将按预期工作,并且重写得很好

我的web.config

<modules runAllManagedModulesForAllRequests="true">
</modules>
<rewrite>
  <rules>
    <rule name="Proxy mobile API" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{REQUEST_URI}" pattern="([^/]+)" />
        <add input="{StaticRewrites:{C:0}}" pattern="(.+)" />
        <add input="{HTTP_HOST}" pattern="^api.mydomain.se$" />
      </conditions>
      <action type="Rewrite" url="http://mobileapi.mydomain.se/{R:0}" />
    </rule>
  </rules>

  <rewriteMaps>
    <rewriteMap name="StaticRewrites">
      <add key="mobile" value=" " />
      <add key="scripts" value=" " />
    </rewriteMap>
  </rewriteMaps>
</rewrite>  

根据您设置的项目类型,但如果您使用的是MVC 4,则只需在Global.asax.cs文件中进行此切换

protected void Application_BeginRequest(){
   //mobile device detection and redirection
     if (Request.Browser["IsMobileDevice"] == "true"){
          Response.Redirect("http://mobileapi.mydomain.se");
         }
    }

根据您设置的项目类型,但如果您使用的是MVC 4,则只需在Global.asax.cs文件中进行此切换

protected void Application_BeginRequest(){
   //mobile device detection and redirection
     if (Request.Browser["IsMobileDevice"] == "true"){
          Response.Redirect("http://mobileapi.mydomain.se");
         }
    }

第一个问题,如果这是显而易见的,很抱歉,但是您是否安装了URL重写模块?更新了问题,使其他重写工作更清楚:还请注意,如果我将操作类型更改为重定向而不是重写,则可以正常工作,但这不是我想要的解决方案。重写是否在applicationHost.config中完成?如果是,但它不起作用,请尝试通过“重写”路由到服务器场。否,重写直接在web中进行。配置第一个问题,如果这很明显,很抱歉,但是您是否安装了URL重写模块?更新了问题,使其他重写工作更清楚:还请注意,如果我将操作类型更改为重定向而不是重写,则可以正常工作,但这不是我想要的解决方案。重写是否在applicationHost.config中完成?如果是,但不起作用,请尝试使用“重写”路由到服务器场。否,重写直接在web.config中进行