![](/img/trans.png)
[英]Redirect to https through url rewrite in IIS within elastic beanstalk's load balancer
[英]Redirect to HTTPS on IIS behind an AWS Load balancer doesn't work in IE
我试图在使用AWS上的Elastic Beanstalk托管的网站上强制使用HTTPS。 因为它在AWS上并且AWS Loadbalancer在IIS上插入了它自己的重定向规则,所以我不能使用Global Filter强制HTTPS。 如果执行此操作,则会收到有关太多重写的错误。
相反,我必须使用UrlRewrite并从web.config传递规则,而我使用的是从SO上的另一个答案获得的规则。 这与强制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>
该规则在Safari和Chrome中有效,但在IE中,用户首次访问该站点时,它是HTTP,直到他们单击链接,然后下一个页面是HTTPS。 这种行为还不错,但是我的索引上有一个表单,当您尝试使用HTTP提交表单时,它将刷新页面并变为HTTPS。 表单提交之后将起作用。
预先感谢您的任何帮助
如果您使用的是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.