2

I'm getting too many redirects with my two rules in IIS. One rule is to redirect all traffic to HTTPS, the other is to redirect to a 'not supported' page for browsers that don't fit my mapped criteria - this page is at the top level of the app. I am trying to exclude this 'NotSupported' page from the HTTPS rule as I believe this is what is causing all the redirects - but, it's not working... Anyone see what I'm doing wrong?

Thanks

<rewrite>
    <rules>
      <rule name="UserAgent MSIE Rewrite" patternSyntax="ECMAScript" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
          <add input="{HTTP_USER_AGENT}" pattern="Chrome|MSIE 8.0|MSIE 7.0b|MSIE 7.0|MSIE 6.0b|MSIE 6.0|MSIE 5.5b1|MSIE 5.5|MSIE 5.0|MSIE 5.01|MSIE 4.0" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/NotSupported.html"   appendQueryString="false" redirectType="Permanent" />
      </rule>
      <rule name="Redirect to HTTPS" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_URI}" negate="true" pattern="^/NotSupported\.html$" ignoreCase="true" />
          <add input="{HTTPS}" pattern="^OFF$" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{REQUEST_URI}" redirectType="Permanent" />
      </rule>
    </rules>
</rewrite>

EDIT:

This works (redirecting to Google)...

<rule name="UserAgent MSIE Rewrite" patternSyntax="ECMAScript" stopProcessing="true"> <match url=".*" ignoreCase="true" negate="false" /> <conditions logicalGrouping="MatchAny" trackAllCaptures="false"> <add input="{REQUEST_URI}" negate="true" pattern="^/notsupported$" ignoreCase="true" /> <add input="{HTTP_USER_AGENT}" pattern="Chrome|MSIE 8.0|MSIE 7.0b|MSIE 7.0|MSIE 6.0b|MSIE 6.0|MSIE 5.5b1|MSIE 5.5|MSIE 5.0|MSIE 5.01|MSIE 4.0" /> </conditions> <action type="Redirect" url="http://www.google.com/" appendQueryString="false" redirectType="Found" /> </rule>

But this doesn't - trying to use an internal address. How can I exclude this rule on that page so it stops the loop?

<rule name="UserAgent MSIE Rewrite" patternSyntax="ECMAScript" stopProcessing="true"> <match url=".*" ignoreCase="true" negate="false" /> <conditions logicalGrouping="MatchAny" trackAllCaptures="false"> <add input="{REQUEST_URI}" negate="true" pattern="^/notsupported$" ignoreCase="true" /> <add input="{HTTP_USER_AGENT}" pattern="Chrome|MSIE 8.0|MSIE 7.0b|MSIE 7.0|MSIE 6.0b|MSIE 6.0|MSIE 5.5b1|MSIE 5.5|MSIE 5.0|MSIE 5.01|MSIE 4.0" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/notsupported.html" appendQueryString="false" redirectType="Found" /> </rule>

Any ideas?

jezorama
  • 347
  • 1
  • 3
  • 13
  • There is an attribute `[RequireHttps]` that you can apply globally or apply to controllers. Just in case you didn't know about it already. – Luke Aug 18 '15 at 10:52
  • I did think about using this: [mvc requirehttps entire site](http://stackoverflow.com/questions/3285014/mvc-requirehttps-entire-site) But I'd like to keep the rule in place as I know it's working for now – jezorama Aug 18 '15 at 10:56
  • 1
    Ah, I think I realise the error of my ways - I've commented out the Redirect to HTTPS rule, and it still causes issues. I think the issue is that it redirects to the notsupported page, then, redirects again, over and over. I need to exclude the notsupported page from the UserAgent Rule...I think! – jezorama Aug 18 '15 at 11:02
  • Yeah my problem still lies with the first UserAgent MSIE Rewrite rule... even when I exclude the URL it doesn't work as it seems to be caught in a loop! – jezorama Aug 18 '15 at 11:13

0 Answers0