我有以下网址
http://www.mywebsite.com/home
https://www.mywebsite.com/secure/reports/
当用户输入上述网址时,我们加载
http://www.mywebsite.com/home.aspx
https://www.mywebsite.com/secure/reports.aspx
问题是,如果用户输入https://www.mywebsite.com/home
,则需要重定向到http://www.mywebsite.com/home
。只需将https更改为http,因为它不受保护
同样,如果用户输入http://www.mywebsite.com/secure/reports
,我们需要redurect以保护https://www.mywebsite.com/secure/reports
答案 0 :(得分:1)
请参阅this:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Request.IsSecureConnection.Equals(false) && HttpContext.Current.Request.IsLocal.Equals(false))
{
Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"]
+ HttpContext.Current.Request.RawUrl);
}
}
答案 1 :(得分:0)
更改您的Web.Config
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions><add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>