IIS http强制转向https(证书已安装好)

1.修改C:\inetpub\custerr\zh-CN\403.htm文件,在标签中添加:

<script type="text/javascript">  
    var url=window.location.href;  
    url=url.replace("http:","https:")  
    window.location.replace(url);
script>

IIS管理中SSL设置的“需要SSL”需要勾选,这样当访问不是http的页面时就会先跳转到403错误页面,然后再跳转到https页面。

2.对于asp.net站点,可以直接修改web.config配置文件:


<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <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>
      rules>
    rewrite>
  system.webServer>
configuration>

你可能感兴趣的:(asp-net)