首先我们申请了自己的域名后,在发布的网站绑定了SSL证书后,能过https://域名的方式直接访问到我们的网页,但是在浏览器里直接输入域名时默认是http://域名的格式,导致提示访问不到网站。
解决办法
在我们发布的程序的web.config文件夹里进行一断代码的增加
<?xml version="1.0" encoding="utf-8"?> <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>
上面这段蓝色的代码复制进去,可实现输入域名直接跳转至https的方式,解决了我们问题。
看一下设置后的图片
红色部分就是我们在发布的web.config里面进行了修改
-END-