2017-06-12
Windows Server 2016 + IIS + Visual Studio 2017
在 Global.asax 檔案中增加
// 自動重導 HTTP 到 HTTPS,IIS 必須 Port 80 和 443 都啟用 void Application_BeginRequest(object sender, EventArgs e) { bool needsSSL = true; if (needsSSL != Request.IsSecureConnection) { if (needsSSL) { Response.Redirect(Uri.UriSchemeHttps + Uri.SchemeDelimiter + Request.Url.Host + Request.Url.PathAndQuery, true); } else { Response.Redirect(Uri.UriSchemeHttp + Uri.SchemeDelimiter + Request.Url.Host + Request.Url.PathAndQuery, true); } } } |
(完)
相關
[IIS] Windows Server 2016 無法安裝 URL Rewrite !?
https://blog.exfast.me/2016/12/iis-windows-server-2016-unable-to-install-url-rewrite/
PS:強行硬裝,不知道 IIS 所有功能能否 100% 使用,不太保險
HTTP to HTTPS redirects on IIS 7.x and higher
https://blogs.msdn.microsoft.com/kaushal/2013/05/22/http-to-https-redirects-on-iis-7-x-and-higher/
Forcing SSL (https) on a page by page basis
https://stackoverflow.com/questions/3681331/forcing-ssl-https-on-a-page-by-page-basis
沒有留言:
張貼留言