简体   繁体   English

重定向到AWS负载均衡器后面的IIS上的HTTPS在IE中不起作用

[英]Redirect to HTTPS on IIS behind an AWS Load balancer doesn't work in IE

I am trying to force HTTPS on my site that is hosted using Elastic Beanstalk on AWS. 我试图在使用AWS上的Elastic Beanstalk托管的网站上强制使用HTTPS。 Because it is on AWS and the AWS Loadbalancer inserts it's own redirect rule on IIS I can't use a Global Filter to force HTTPS. 因为它在AWS上并且AWS Loadbalancer在IIS上插入了它自己的重定向规则,所以我不能使用Global Filter强制HTTPS。 If I do this I get an error about too many rewrites. 如果执行此操作,则会收到有关太多重写的错误。

Instead I have to use UrlRewrite and pass a rule from my web.config I'm using the rule that I got from another answer on SO. 相反,我必须使用UrlRewrite并从web.config传递规则,而我使用的是从SO上的另一个答案获得的规则。 This is very similar to most of the answers out there for forcing HTTPS 这与强制HTTPS的大多数答案非常相似

<rule name="HTTP to HTTPS" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" negate="true" />
        <add input="{HTTPS}" pattern="^OFF$" ignoreCase="true"/>
        <add input="{REMOTE_HOST}" pattern="localhost" negate="true" />
        <add input="{REMOTE_ADDR}" pattern="127.0.0.1" negate="true" />
        <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>

This rule works in Safari & Chrome, but in IE the first time the user goes to the site it is HTTP until they click a link and then the next page is HTTPS. 该规则在Safari和Chrome中有效,但在IE中,用户首次访问该站点时,它是HTTP,直到他们单击链接,然后下一个页面是HTTPS。 This behavior isn't too bad, but I have a form on my index and when you try to submit that in HTTP it refreshes the page and becomes HTTPS. 这种行为还不错,但是我的索引上有一个表单,当您尝试使用HTTP提交表单时,它将刷新页面并变为HTTPS。 The form submit works after that. 表单提交之后将起作用。

Thanks in advance for any help 预先感谢您的任何帮助

If you are using asp.net mvc, you can use this code in your application class instead of configuration 如果您使用的是asp.net mvc,则可以在应用程序类中使用此代码,而不是进行配置

public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            //Enforce Https to the web app.
            GlobalFilters.Filters.Add(new RequireHttpsAttribute());
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM