将来自www.example.com的所有流量重定向到IIS7中的特定页面

时间:2013-05-29 18:16:50

标签: c# asp.net iis-7 url-rewriting url-redirection

我想将所有传入的流量从http://www.example.com重定向到 http://www.mysite.com/badreferer.aspx?bad=true

我正在研究IIS7和asp.net 4.0以及c#。

我有什么方法可以在IIS7中进行配置吗?

<rule name="bad referer" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_REFERER}" pattern="(.*)example.com(.*)" /> 
    <add input="{HTTP_REFERER}" pattern="(.*)example2.com(.*)" />                        
  </conditions>
  <action type="Redirect" url="/badreferer.aspx?bad=true" appendQueryString="false" />          
</rule>

此规则会产生错误The webpage at http://www.mysite.com/badreferer.aspx?bad=true has resulted in too many redirects

1 个答案:

答案 0 :(得分:0)

您可以使用Response.PermanentRedirect。有关更多信息,请访问以下链接。

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.redirectpermanent.aspx