ASP.NET站点。将整个域从http重定向到https

时间:2012-09-13 11:41:45

标签: asp.net redirect iirf

就像在标题中一样。例如,如何重定向整个域名: http://testdomain.com.au/ https://testdomain.com.au/ 我能否在IIRF文件中执行此操作?如果是,这应该是什么样子?如何将IIRF文件绑定到站点?

1 个答案:

答案 0 :(得分:9)

您可以通过IIS Rewrite module

执行此操作

http://www.iis.net/downloads/microsoft/url-rewrite

http://www.iis-aid.com/articles/how_to_guides/redirect_http_to_https_iis_7

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
  <match url="(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
   <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>

或者您可以通过Global.asax文件重定向:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if ( !Request.IsSecureConnection)
    {
            string path = string.Format("https{0}", Request.Url.AbsoluteUri.Substring(4)); 

            Response.Redirect(path);
    }
}

http://forums.asp.net/t/1340392.aspx