大约6个月前,我推出了一个网站,每个请求都需要通过https.当我找到确保页面的每个请求都通过https的唯一方法是在页面加载事件中检查它.如果请求不是通过http,我会response.redirect(" https://example.com ")
有没有更好的方法 - 理想情况下web.config中的一些设置?
我需要将所有https请求重定向到http,例如,如果有人访问https://www.example.com/another-page/,请访问http://www.example.com/another-page/
我现在在web.config中有以下重写规则,但它无法正常工作.它将https://www.example.com/another-page/重定向到https://www.example.com/,所以到了网站的根目录,但我希望重定向保留在同一个网址中将https重写为http.
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{R:1}" pattern="^onepage/(.*)$" negate="true" />
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
任何有关更改上述规则的帮助,以便它只将https更改为http,但保持访问的完整网址将非常感谢!
我在我的MVC Web API 2控制器中创建了以下操作:
[ResponseType(typeof(int))]
[RequireHttps]
public IHttpActionResult SaveLead(EcommerceLead lead)
{
}
Run Code Online (Sandbox Code Playgroud)
但在我的测试应用程序中,我正在打电话给
http://localhost/api/savelead
Run Code Online (Sandbox Code Playgroud)
它正在发挥作用.是否有任何方法可以使操作仅在通过https调用时才起作用,即如果不是或返回404,则返回404?
我正在尝试强制执行https和www前缀.但是我的规则并不完全有效.这是我的规则:
<rewrite>
<rules>
<clear />
<rule name="Force https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.mydomain.co.uk/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Force www" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
<add input="{HTTP_HOST}" pattern="www.mydomain.co.uk" negate="true" />
</conditions>
<action type="Redirect" url="https://www.mydomain.co.uk/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
有人可以建议吗?谢谢.