繁体   English   中英

用https重写网址

[英]Url rewriting with https

我有以下网址

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 ,我们需要重新加密以保护https://www.mywebsite.com/secure/reports

看到这个

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);
   }
}

更改您的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>

更多参考:Check- http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/

暂无
暂无

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

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